Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Create Custom Taxonomies for Better Content Organization

- 06.06.26 - ErcanOPAK

🏷️ More Than Categories and Tags

Posts have categories, tags. Products need brands, sizes, colors. Custom taxonomies create any classification system.

📝 Register Custom Taxonomy

// functions.php
function create_product_taxonomies() {
    // Brand taxonomy (hierarchical like categories)
    register_taxonomy('product_brand', 'product', array(
        'labels' => array(
            'name' => 'Brands',
            'singular_name' => 'Brand',
            'search_items' => 'Search Brands',
            'all_items' => 'All Brands',
            'parent_item' => 'Parent Brand',
            'parent_item_colon' => 'Parent Brand:',
            'edit_item' => 'Edit Brand',
            'update_item' => 'Update Brand',
            'add_new_item' => 'Add New Brand',
            'new_item_name' => 'New Brand Name',
            'menu_name' => 'Brands'
        ),
        'hierarchical' => true,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'brand'),
        'show_in_rest' => true  // Block editor support
    ));
    
    // Size taxonomy (non-hierarchical like tags)
    register_taxonomy('product_size', 'product', array(
        'labels' => array(
            'name' => 'Sizes',
            'singular_name' => 'Size',
            'search_items' => 'Search Sizes',
            'popular_items' => 'Popular Sizes',
            'all_items' => 'All Sizes',
            'edit_item' => 'Edit Size',
            'update_item' => 'Update Size',
            'add_new_item' => 'Add New Size',
            'new_item_name' => 'New Size Name',
            'menu_name' => 'Sizes'
        ),
        'hierarchical' => false,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'size'),
        'show_in_rest' => true
    ));
}
add_action('init', 'create_product_taxonomies');

🎯 Display Taxonomy in Template

// Get terms for current post
$brands = get_the_terms(get_the_ID(), 'product_brand');
if ($brands && !is_wp_error($brands)) {
    echo '<div class="product-brand">Brand: ';
    foreach ($brands as $brand) {
        echo '<a href="' . get_term_link($brand) . '">' . $brand->name . '</a>';
    }
    echo '</div>';
}

// Query products by brand
$args = array(
    'post_type' => 'product',
    'tax_query' => array(
        array(
            'taxonomy' => 'product_brand',
            'field' => 'slug',
            'terms' => 'nike'
        )
    )
);
$query = new WP_Query($args);

💡 Use Cases

  • Products: Brands, Sizes, Colors, Materials
  • Recipes: Cuisine, Diet, Difficulty, Cooking Time
  • Movies: Genre, Director, Actor, Year
  • Real Estate: Property Type, Location, Price Range

“Categories and tags weren’t enough for products. Added Brand taxonomy. Now customers can filter by brand. SEO improved because brand pages have unique content.”

— WooCommerce Developer

Related posts:

WordPress: Boosting API Performance with the Transients API

Stop Using Plugins for Dynamic Content: Use Conditional Blocks Instead

WordPress: Finding the Plugin That's Slowing You Down

Post Views: 4

Post navigation

Photoshop: Use Frequency Separation for Professional Skin Retouching
Kubernetes: Use Priority Classes to Ensure Critical Pods Run First

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

June 2026
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  
« May    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (882)
  • Get the First and Last Word from a String or Sentence in SQL (838)
  • How to select distinct rows in a datatable in C# (808)
  • How to make theater mode the default for Youtube (805)
  • Add Constraint to SQL Table to ensure email contains @ (580)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (579)
  • Average of all values in a column that are not zero in SQL (538)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (505)
  • Find numbers with more than two decimal places in SQL (454)

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files
  • Ajax: Add Custom Headers to Fetch Requests
  • JavaScript: Use console.table to Display Arrays as Tables
  • HTML: Use Spellcheck Attribute to Enable Browser Spell Check
  • CSS: Use user-select to Prevent Text Selection
  • Windows 11: Use Snipping Tool for Instant Screenshots

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (882)
  • Get the First and Last Word from a String or Sentence in SQL (838)
  • How to select distinct rows in a datatable in C# (808)
  • How to make theater mode the default for Youtube (805)

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com