Introduction
When building complex websites in WordPress, organizing content becomes very important. While Custom Post Types allow developers to create different types of content, Taxonomies help organize and classify that content.
For example, a website that uses a Portfolio Custom Post Type may want to categorize projects based on:
- Project type
- Technologies used
- Industry
Taxonomies make it easier to group related content together and help users navigate the website more efficiently.
When building complex websites in WordPress, organizing content becomes very important. While Custom Post Types allow developers to create different types of content, Taxonomies help categorize and structure that content in a meaningful way.
In this tutorial, you will learn what taxonomies are, how they work in WordPress, and how to create custom taxonomies for Custom Post Types.
What are Taxonomies in WordPress?
A taxonomy is a system used to classify and organize content so that related items can be grouped together and easily discovered by users.
WordPress already includes two built-in taxonomies:
| Taxonomy | Used For |
|---|---|
| Categories | Grouping posts into broad topics |
| Tags | Adding specific keywords to posts |
Taxonomies allow WordPress to structure content in a meaningful way so that related items can be grouped together.
For example:
A blog about technology might have categories such as:
- Programming
- Web Development
- Cybersecurity
Tags might include:
- PHP
- WordPress
- JavaScript
Why Use Custom Taxonomies with CPT?
Custom taxonomies are useful when your website uses Custom Post Types and needs a way to organize that content.
For example:
Portfolio website:
Custom Post Type → Portfolio
Possible Taxonomies:
- Project Type
- Technology Used
- Client Industry
Real estate website:
Custom Post Type → Properties
Possible Taxonomies:
- Property Type
- Location
- Property Status
Custom taxonomies help create a structured system for organizing content.
How Taxonomies Work with Custom Post Types
When you create a Custom Post Type, you can attach taxonomies to it.
For example:
Portfolio Post Type → Project Type taxonomy
This allows each portfolio item to be assigned to one or more categories such as:
- Web Development
- Mobile Apps
- UI/UX Design
WordPress automatically generates archive pages for taxonomy terms.
Example:
yoursite.com/project-type/web-development
These pages display all portfolio items that belong to that taxonomy term.
Creating a Custom Taxonomy (Code Example)
function register_project_taxonomy() {
$labels = array(
'name' => 'Technologies',
'singular_name' => 'Technology',
'search_items' => 'Search Technologies',
'all_items' => 'All Technologies',
'edit_item' => 'Edit Technology',
'update_item' => 'Update Technology',
'add_new_item' => 'Add New Technology',
'new_item_name' => 'New Technology Name',
'menu_name' => 'Technologies',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'rewrite' => array('slug' => 'technology'),
);
register_taxonomy('technology', array('project'), $args);
}
add_action('init', 'register_project_taxonomy');
Understanding the Code
Let’s break down the important parts of the code.
register_taxonomy(‘technology’)
This defines the internal name (slug) of the taxonomy.
‘project’
This tells WordPress that the taxonomy is attached to the Project Custom Post Type.
label
This defines the name displayed in the WordPress dashboard.
Example:
Technologies
rewrite
This defines the URL structure.
Example URL:
yoursite.com/technology/
Hierarchical vs Non-Hierarchical Taxonomies
Taxonomies in WordPress can behave either like categories or like tags, depending on the configuration.
| Type | Example | Behavior |
|---|---|---|
| Hierarchical | Categories | Parent-child structure |
| Non-Hierarchical | Tags | Flat structure |
Change:
'hierarchical' => false
Attach Existing Taxonomy to CPT
Sometimes you may want to attach an existing taxonomy (such as Categories) to a Custom Post Type.
register_taxonomy_for_object_type( 'category', 'project' );
Using Multiple Taxonomies
A Custom Post Type can have multiple taxonomies.
Example for a Portfolio website:
Portfolio Post Type
Taxonomies:
- Project Type
- Technologies Used
- Client Industry
This makes content much easier to organize and filter.
Display Taxonomies on Frontend
To display taxonomy terms assigned to a post, you can use the get_the_terms() function.
$terms = get_the_terms( get_the_ID(), 'technology' );if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
echo '<span>' . esc_html( $term->name ) . '</span> ';
}
}
Create Taxonomy Archive Pages
WordPress auto-generates:
/technology/php/
/technology/wordpress/
Optional custom template:
taxonomy-technology.php
SEO Tips for Custom Taxonomies
- Use meaningful slugs
- Add description for each term
- Enable taxonomy archives
- Internally link taxonomy pages
- Avoid creating too many thin taxonomies
Refresh Permalinks After Creating Taxonomies
After creating a new taxonomy, WordPress may not immediately recognize the new URL structure.
To fix this:
- Go to Settings → Permalinks in the WordPress dashboard.
- Click Save Changes without modifying anything.
This refreshes WordPress rewrite rules and ensures taxonomy archive pages work correctly.
Common Mistakes
- Creating too many taxonomies
- Using tags when categories are needed
- Not setting rewrite rules
- Forgetting to flush permalinks
Practical Tasks (Assignments)
- Create a CPT called
portfolio - Create taxonomy
tools - Add 5 terms (PHP, HTML, CSS, WordPress, MySQL)
- Assign terms to portfolio items
- Create taxonomy archive template
- Display taxonomy terms on single post page
Conclusion
Custom taxonomies make Custom Post Types more powerful by allowing developers to organize content in a structured way.
When combined with Custom Post Types, custom fields, and templates, taxonomies allow developers to build advanced content management systems inside WordPress.
In the next tutorial, we’ll learn about Creating Custom WordPress Dashboard Widget.
