How to Create Custom Taxonomies in WordPress

A comprehensive guide to organizing your content with custom taxonomies using code and modern plugins

Custom taxonomies in WordPress provide a powerful way to organize and classify content beyond the default categories and tags. Whether you're building a portfolio site, an e-commerce platform, or a complex content hub, understanding how to create custom taxonomies gives you fine-grained control over your content structure. This guide covers both code-based approaches using register_taxonomy() and modern plugin alternatives for implementing taxonomies in WordPress.

For professional WordPress development services that help you build scalable content architectures, our team specializes in custom WordPress solutions tailored to your business needs.

What Are WordPress Taxonomies?

Taxonomies in WordPress are ways to group content together. The platform comes with two built-in taxonomies: categories (hierarchical, meaning they can have parent-child relationships) and tags (non-hierarchical, flat structure). Custom taxonomies allow you to create additional grouping systems tailored to your specific content model. For example, a movie review site might create a "genre" taxonomy, while a real estate website could implement "property type" or "location" taxonomies.

Custom taxonomies are essential when your content model doesn't fit neatly into categories and tags. A book review site might need "author," "publisher," "genre," and "reading level" taxonomies, each serving a different organizational purpose. The flexibility to create exactly the classification system your content requires is one of WordPress's most powerful features for content architecture.

Understanding Hierarchical vs Non-Hierarchical Taxonomies

When creating a custom taxonomy, you'll choose between hierarchical and non-hierarchical structures. Hierarchical taxonomies, like categories, allow terms to have parent-child relationships--"Electronics" could contain "Computers" and "Phones" as child terms. Non-hierarchical taxonomies, like tags, are flat lists where all terms exist at the same level. Your choice depends on whether your content organization needs nested categories or a flat tagging system.

Taxonomy Type Comparison

Hierarchical Taxonomies

Category-like structure with parent-child relationships. Supports dropdown selectors, nested URLs, and infinite term depth. Ideal for organizational hierarchies like product categories or organizational structure.

Non-Hierarchical Taxonomies

Tag-like flat structure with no nesting. Uses comma-separated input fields, simpler organization, and best for attributes where relationships don't matter, like keywords or technical specifications.

Creating Taxonomies with Code

The code-based approach to creating custom taxonomies gives you maximum control and is ideal for themes or plugins you distribute. The core function is register_taxonomy(), which you hook to the init action. This method requires understanding the function's parameters but offers the cleanest implementation without plugin dependencies.

Code-based taxonomies are portable across themes and can be included in your custom plugins. This approach ensures that your content organization survives theme changes and can be easily replicated across different WordPress installations. For professional WordPress development, the code-based approach is the standard practice and integrates seamlessly with our comprehensive web development services.

The register_taxonomy() Function

The register_taxonomy() function is the foundation of code-based taxonomy creation. It accepts three main parameters: the taxonomy name (a string identifier), the object type (usually 'post' or a custom post type name), and an array of arguments configuring the taxonomy's behavior.

According to the WP Engine guide on custom taxonomies, proper taxonomy registration requires attention to labels, capabilities, and REST API support for modern WordPress development.

Hierarchical Taxonomy Registration
1function create_book_taxonomy() {2 $args = array(3 'hierarchical' => true,4 'labels' => array(5 'name' => _x('Book Categories', 'taxonomy general name'),6 'singular_name' => _x('Book Category', 'taxonomy singular name'),7 'search_items' => __('Search Book Categories'),8 'all_items' => __('All Book Categories'),9 'parent_item' => __('Parent Book Category'),10 'parent_item_colon' => __('Parent Book Category:'),11 'edit_item' => __('Edit Book Category'),12 'update_item' => __('Update Book Category'),13 'add_new_item' => __('Add New Book Category'),14 'new_item_name' => __('New Book Category Name'),15 'menu_name' => __('Book Categories'),16 ),17 'show_ui' => true,18 'show_admin_column' => true,19 'query_var' => true,20 'rewrite' => array('slug' => 'books/category'),21 'show_in_rest' => true,22 );23 24 register_taxonomy('book_category', array('book'), $args);25}26add_action('init', 'create_book_taxonomy');

This example creates a hierarchical "Book Category" taxonomy attached to a custom post type called "book." The labels array defines the text that appears throughout the WordPress admin interface. The show_admin_column parameter determines whether terms appear in the post listing table, while show_in_rest enables REST API support for block editor integration.

As noted in the Let's Go Dev WordPress handbook, proper label configuration is essential for internationalization and provides a professional admin experience.

Creating Non-Hierarchical Taxonomies

Non-hierarchical taxonomies work like tags--terms exist at a single level without parent-child relationships. This is useful for attributes like "author," "genre," or any classification where nested categories don't make sense.

Non-Hierarchical Taxonomy Registration
1function create_book_tags() {2 $args = array(3 'hierarchical' => false,4 'labels' => array(5 'name' => _x('Book Tags', 'taxonomy general name'),6 'singular_name' => _x('Book Tag', 'taxonomy singular name'),7 'search_items' => __('Search Book Tags'),8 'all_items' => __('All Book Tags'),9 'edit_item' => __('Edit Book Tag'),10 'update_item' => __('Update Book Tag'),11 'add_new_item' => __('Add New Book Tag'),12 'new_item_name' => __('New Book Tag Name'),13 'menu_name' => __('Book Tags'),14 ),15 'show_ui' => true,16 'show_admin_column' => true,17 'query_var' => true,18 'rewrite' => array('slug' => 'books/tag'),19 'show_in_rest' => true,20 );21 22 register_taxonomy('book_tag', array('book'), $args);23}24add_action('init', 'create_book_tags');

The key difference is setting 'hierarchical' => false. This creates a tag-like interface in the WordPress admin where terms are added via a simple input field rather than a hierarchical dropdown. According to WPBeginner's taxonomy tutorial, non-hierarchical taxonomies are often used for descriptive attributes that don't need organizational hierarchy.

Attaching Taxonomies to Custom Post Types

Custom taxonomies gain their power when attached to custom post types. When registering a custom post type with register_post_type(), you specify which taxonomies it should use through the 'taxonomies' argument. This creates the relationship between your content and its classifications.

As documented by WP Engine, the proper order of registration matters--taxonomies should be registered before or at the same time as post types that use them to ensure all relationships are properly established.

Registering CPT with Taxonomies
1register_post_type('book', array(2 'labels' => array(3 'name' => __('Books'),4 'singular_name' => __('Book'),5 ),6 'public' => true,7 'has_archive' => true,8 'supports' => array('title', 'editor', 'thumbnail'),9 'taxonomies' => array('book_category', 'book_tag'),10 'rewrite' => array('slug' => 'books'),11));12 13// The taxonomy must be registered BEFORE or with the same hook as the CPT14register_taxonomy('book_category', array('book'), $args);15register_taxonomy('book_tag', array('book'), $args);

Using Plugin Solutions

For users who prefer a no-code approach, several plugins provide graphical interfaces for creating custom taxonomies. These tools are particularly valuable for clients who need to manage taxonomies without touching code, and they often include additional features like advanced filtering and relationship management.

Custom Post Type UI

The Custom Post Type UI plugin by WebDevStudio provides a user-friendly interface for creating both custom post types and taxonomies without writing code. After installing the plugin, navigate to "Add New" under the CPT UI menu to create your taxonomy. The plugin generates the necessary code and handles all the registration details for you.

According to WPBeginner's comparison of taxonomy tools, CPT UI is an excellent starting point for users new to custom taxonomies, with the added benefit that you can export the generated code for use in themes or custom plugins.

Pods Framework

Pods extends beyond simple taxonomy creation by providing a complete content management framework. With Pods, you can create custom taxonomies alongside custom post types and tables, with advanced relationship definitions. The plugin's interface allows you to configure every aspect of your taxonomy, including custom fields attached to terms.

Pods is particularly valuable when you need complex relationships between content types or want to extend term metadata beyond WordPress's default fields. For projects requiring sophisticated content modeling, Pods offers capabilities that approach a full custom development solution.

Advanced Custom Fields

Advanced Custom Fields (ACF) offers taxonomy field types that let you select terms from existing taxonomies in your custom meta boxes. While ACF doesn't create taxonomies directly, its taxonomy field provides a superior interface for selecting terms compared to the default WordPress meta box, with options for return formats, placeholder text, and conditional logic.

As explained in the ACF blog on taxonomy integration, ACF's taxonomy field is ideal when you want to control exactly how term selection works in your custom publishing workflows.

ACF Taxonomy Field Configuration
1acf_add_local_field_group(array(2 'key' => 'group_book_details',3 'title' => 'Book Details',4 'fields' => array(5 array(6 'key' => 'field_author',7 'label' => 'Author',8 'name' => 'author',9 'type' => 'taxonomy',10 'taxonomy' => 'book_author',11 'return_format' => 'id',12 'field_type' => 'select',13 'allow_null' => 0,14 'add_term' => 1,15 ),16 ),17 'location' => array(18 array(19 array(20 'param' => 'post_type',21 'operator' => '==',22 'value' => 'book',23 ),24 ),25 ),26));

Taxonomy Template Files

WordPress uses a template hierarchy to display taxonomy archive pages. When a visitor views a taxonomy term page, WordPress searches for template files in a specific order. Understanding this hierarchy allows you to create custom displays for your taxonomies.

The Let's Go Dev WordPress handbook emphasizes that proper template naming is critical--WordPress follows a strict priority order when selecting which template file to use for taxonomy displays.

The template hierarchy for taxonomies looks for these files in order: taxonomy-{taxonomy}-{term}.php (most specific), taxonomy-{taxonomy}.php, taxonomy.php, archive.php, and finally index.php as a fallback. For example, if your taxonomy is "book_category" and the term is "fiction," WordPress would look for taxonomy-book_category-fiction.php first.

Custom Taxonomy Template (taxonomy-book_category.php)
1<?php2/**3 * Taxonomy Template: book_category4 * Displays posts grouped by book category5 */6 7get_header();8 9$term = get_queried_object();10?>11 12<div class="taxonomy-archive">13 <header class="archive-header">14 <h1><?php echo esc_html($term->name); ?></h1>15 <?php if ($term->description) : ?>16 <p><?php echo esc_html($term->description); ?></p>17 <?php endif; ?>18 </header>19 20 <?php if (have_posts()) : ?>21 <div class="book-grid">22 <?php while (have_posts()) : the_post(); ?>23 <article <?php post_class('book-card'); ?>>24 <?php if (has_post_thumbnail()) : ?>25 <div class="book-cover">26 <?php the_post_thumbnail('medium'); ?>27 </div>28 <?php endif; ?>29 30 <h2><?php the_title(); ?></h2>31 32 <div class="book-meta">33 <?php34 $authors = get_the_terms(get_the_ID(), 'book_author');35 if ($authors && !is_wp_error($authors)) {36 echo '<span class="author">By: ';37 $author_names = wp_list_pluck($authors, 'name');38 echo implode(', ', $author_names);39 echo '</span>';40 }41 ?>42 </div>43 </article>44 <?php endwhile; ?>45 </div>46 47 <?php the_posts_navigation(); ?>48 49 <?php else : ?>50 <p><?php _e('No books found in this category.', 'textdomain'); ?></p>51 <?php endif; ?>52</div>53 54<?php get_footer(); ?>

Displaying Taxonomy Terms

WordPress provides several functions for displaying taxonomy terms in your templates. The most commonly used functions include get_the_term_list() (which returns an HTML string of linked terms), the_terms() (which echoes the terms directly), and get_terms() (which retrieves an array of term objects for custom formatting).

WPBeginner's taxonomy tutorial covers these functions in depth, emphasizing that choosing the right function depends on how you need to style and format your term output.

Methods for Displaying Taxonomy Terms
1// Method 1: Simple list with the_terms()2the_terms(get_the_ID(), 'book_category', '<p class="categories">Categories: ', ', ', '</p>');3 4// Method 2: Custom formatted list with get_the_term_list()5$categories = get_the_term_list(get_the_ID(), 'book_category', '<li class="cat-item">', '</li><li class="cat-item">', '</li>');6if ($categories) {7 echo '<ul class="category-list">' . $categories . '</ul>';8}9 10// Method 3: Full control with get_terms()11$terms = get_terms(array(12 'taxonomy' => 'book_category',13 'hide_empty' => true,14 'parent' => 0,15));16 17if ($terms && !is_wp_error($terms)) {18 echo '<div class="term-cloud">';19 foreach ($terms as $term) {20 echo '<a href="' . get_term_link($term) . '" class="term-link">';21 echo $term->name . ' (' . $term->count . ')';22 echo '</a>';23 }24 echo '</div>';25}

REST API and Gutenberg Integration

Modern WordPress development requires taxonomies to work with the REST API and block editor. Setting 'show_in_rest' => true in your taxonomy arguments enables REST API endpoints and ensures the taxonomy appears in the Gutenberg sidebar meta box. Without this setting, your taxonomy won't be available in the block editor or to external applications accessing your site's API.

According to Let's Go Dev's modern WordPress development guide, REST API support is essential for headless WordPress configurations and any project that needs to expose content to external applications.

URL Rewriting and Permalinks

The rewrite argument in register_taxonomy() controls your taxonomy's URL structure. Proper URL rewriting is crucial for SEO and user experience. After changing rewrite settings, remember to visit Settings > Permalinks and save to flush the rewrite rules.

Rewrite Configuration Options
1'rewrite' => array(2 'slug' => 'books/genre', // Base slug in URLs3 'with_front' => true, // Use prefix from permalink structure4 'hierarchical' => true, // Enable hierarchical URLs like /books/genre/fiction/mystery/5 'ep_mask' => EP_CATEGORIES, // Endpoint mask for URL rewriting6),

The hierarchical rewrite option creates breadcrumb-friendly URLs where parent categories appear in the path. This improves both user navigation and search engine understanding of your content structure. For e-commerce sites, this URL structure helps customers navigate product categories intuitively while signaling the content hierarchy to search engines.

When implementing custom taxonomies for SEO purposes, proper URL structure contributes to your overall search engine optimization strategy.

Best Practices

Following WordPress coding standards and best practices ensures your custom taxonomies integrate smoothly with themes, plugins, and future WordPress versions. Always prefix your taxonomy names to avoid conflicts, use the proper hook priority, and provide complete label arrays for internationalization.

The WP Engine taxonomy guide and Let's Go Dev handbook both emphasize these standards as essential for professional WordPress development.

Use meaningful prefixes based on your project or company name, such as 'myproject_' for a project called "My Project." This prevents conflicts with other plugins or themes that might use generic names like 'genre' or 'type.' When creating taxonomies for client projects, include proper text domain references for translation readiness.

Additionally, consider performance implications when designing taxonomies with many terms. Use 'hide_empty' => true in get_terms() calls to avoid loading unused terms, and implement caching for taxonomy queries on high-traffic sites.

Common Issues and Troubleshooting

When taxonomies don't appear as expected, common causes include incorrect hook priority (taxonomies must be registered before post types that use them), missing rewrite flushing, or conflicts with other plugins. Use wp_debug mode to identify PHP errors, and check that your template files follow the correct naming convention.

If your taxonomy terms return 404 errors, the rewrite rules likely need flushing. This happens after adding new taxonomies or changing their slug. Simply visiting the Permalinks settings page and saving (without making changes) refreshes the rewrite rules and resolves most 404 issues. For more complex problems, check your web server's error logs and ensure that your permalink structure isn't being overridden by server configuration.

Frequently Asked Questions

Conclusion

Custom taxonomies are essential for organizing content in ways that default categories and tags can't accommodate. Whether you choose the code-based approach for maximum control or plugin solutions for easier client management, understanding the register_taxonomy() function and its parameters gives you a foundation for building sophisticated content structures. Remember to follow WordPress coding standards, enable REST API support for modern integrations, and test your taxonomy implementations thoroughly before deployment.

For complex WordPress projects, consider how custom taxonomies fit into your broader WordPress development strategy. Proper content organization through taxonomies improves both user experience and search engine visibility, making them a critical component of any well-structured WordPress site. Our team can help you design and implement custom taxonomies that scale with your business and integrate seamlessly with your web development initiatives.

Need Help with WordPress Custom Taxonomies?

Our WordPress development team can help you design and implement custom content organization systems that scale with your business.

Sources

  1. WP Engine - How to Create Custom Taxonomies in WordPress - Authoritative WordPress hosting provider guide with detailed code examples
  2. Advanced Custom Fields - Custom Taxonomy in WordPress - Official ACF documentation on taxonomy field integration
  3. Let's Go Dev - Create a Custom Taxonomy in WordPress: Complete Guide - Comprehensive developer handbook with modern WordPress practices
  4. WPBeginner - Create Custom Taxonomies WordPress - Popular WordPress tutorial site with beginner-friendly explanations