Introduction: Organizing Your Custom Content
You’ve already built a lightning-fast Custom Post Type (CPT) called “Reviews.”
But now, if you try to categorize your reviews, you’ll hit a wall — WordPress only includes the default Categories and Tags, which belong to regular blog posts.
You don’t want a “Review” categorized under “News,” do you?
That’s where Custom Taxonomies come in. They let you create new organizational structures (like Categories or Tags) that belong exclusively to your Custom Post Types.
For our “Review” CPT, we’ll create a custom taxonomy called “Genre.”
Why Code Instead of Using Plugins?
By coding taxonomies manually, you:
- Keep your site lightweight and fast
- Maintain full control over structure
- Avoid plugin dependency and conflicts
We’ll add this taxonomy using just your theme’s functions.php
file — no plugin bloat needed.
Prerequisites
Before you start:
- You must already have a Review CPT (slug:
review
) registered. - We’ll continue editing your child theme’s
functions.php
file via your local setup or FTP.
Phase 1: The Code Container and Hook
Just like with CPTs, we’ll wrap the taxonomy code inside a function and hook it into WordPress’ loading process.
Step 1: Define the Function
Add this code below your register_review_cpt()
function inside functions.php
:
// 1. Define the function for the new taxonomy
function register_review_taxonomy() {
// All our taxonomy code will go here...
}
// 2. Tell WordPress to run this code on initialization
add_action( 'init', 'register_review_taxonomy', 0 );
Phase 2: Defining Labels and Arguments
WordPress needs two arrays:
$labels
— for how your taxonomy appears in the Admin UI.$args
— for how it behaves across your website.
Step 2: Define the Taxonomy Labels
These define how your new “Genre” system appears in the admin dashboard:
// --- INSIDE register_review_taxonomy() ---
$labels = array(
'name' => _x( 'Genres', 'Taxonomy General Name', 'textdomain' ),
'singular_name' => _x( 'Genre', 'Taxonomy Singular Name', 'textdomain' ),
'menu_name' => __( 'Genres', 'textdomain' ),
'all_items' => __( 'All Genres', 'textdomain' ),
'new_item_name' => __( 'New Genre Name', 'textdomain' ),
'add_new_item' => __( 'Add New Genre', 'textdomain' ),
'update_item' => __( 'Update Genre', 'textdomain' ),
'view_item' => __( 'View Genre', 'textdomain' ),
'separate_items_with_commas' => __( 'Separate Genres with commas', 'textdomain' ),
'add_or_remove_items' => __( 'Add or remove Genres', 'textdomain' ),
);
Step 3: Define the Taxonomy Arguments
This array controls how your taxonomy behaves and displays:
// --- INSIDE register_review_taxonomy() ---
$args = array(
'labels' => $labels,
'hierarchical' => true, // TRUE = acts like Categories (parent/child)
'public' => true,
'show_ui' => true,
'show_admin_column' => true, // Shows Genres in the CPT list view
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ), // URL: /genre/action/
'show_in_rest' => true, // Enables Gutenberg support
);
Phase 3: Register the Taxonomy and Bind It to Your CPT
Now, we’ll officially register the taxonomy and link it to the existing Review post type.
Step 4: Register the Taxonomy and Link the CPT
// --- INSIDE register_review_taxonomy() ---
// Syntax: register_taxonomy( $taxonomy_slug, $post_type_slug_or_array, $args )
register_taxonomy( 'review_genre', 'review', $args );
Step 5: Flush Permalinks
After saving your functions.php
, you must refresh WordPress’ URL structure:
- Go to Settings → Permalinks
- Click Save Changes (no edits needed)
Now you’ll see a new “Genres” submenu under your “Reviews” CPT.
Design Synergy: Filtering Power (By Zara)
Architect’s Tip:
Taxonomies are how advanced websites handle smart filtering.
By separating “Review Genres” from default post categories, you enable dynamic front-end filtering — e.g. “Show all Action reviews with a 5-star rating.”
In our next guide, we’ll expand this with custom fields for ratings and scores — giving you a complete, professional data structure.
The Complete Code (Copy & Paste)
Here’s the entire function for your Review Genre taxonomy:
// ==========================================================
// CUSTOM TAXONOMY: Review Genre (for the 'review' CPT)
// ==========================================================
function register_review_taxonomy() {
// 1. LABELS
$labels = array(
'name' => _x( 'Genres', 'Taxonomy General Name', 'textdomain' ),
'singular_name' => _x( 'Genre', 'Taxonomy Singular Name', 'textdomain' ),
'menu_name' => __( 'Genres', 'textdomain' ),
'all_items' => __( 'All Genres', 'textdomain' ),
'new_item_name' => __( 'New Genre Name', 'textdomain' ),
'add_new_item' => __( 'Add New Genre', 'textdomain' ),
'update_item' => __( 'Update Genre', 'textdomain' ),
'view_item' => __( 'View Genre', 'textdomain' ),
'separate_items_with_commas' => __( 'Separate Genres with commas', 'textdomain' ),
'add_or_remove_items' => __( 'Add or remove Genres', 'textdomain' ),
);
// 2. ARGUMENTS
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
'show_in_rest' => true,
);
// 3. REGISTER
register_taxonomy( 'review_genre', 'review', $args );
}
add_action( 'init', 'register_review_taxonomy', 0 );
Conclusion and Next Steps
You’ve now built the second major piece of your custom content system — the taxonomy.
Your “Reviews” are now organized by “Genre,” completely separate from the main blog categories.
You’ve got:
- Clean structure
- Full control
- Plugin-free speed
Now it’s time to enrich your Reviews with more data!
👉 Read our next guide: Mastering Custom Fields in WordPress (The ACF Plugin Alternative)