🏷️ Custom Taxonomies = Better Organization
Categories and tags are basic. Custom taxonomies organize content better. Any structure, any purpose.
📝 Register Custom Taxonomy
// functions.php
function register_portfolio_taxonomy() {
register_taxonomy('portfolio_type', 'portfolio',
array(
'labels' => array(
'name' => 'Types',
'add_new_item' => 'Add New Type'
),
'hierarchical' => true,
'show_in_rest' => true,
'rewrite' => array('slug' => 'portfolio-type')
)
);
}
add_action('init', 'register_portfolio_taxonomy');
# Taxonomy Types
- Hierarchical (like categories)
- Non-hierarchical (like tags)
# Taxonomy Options
'hierarchical' => true, // Categories
'hierarchical' => false, // Tags
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true, // Gutenberg support
# Query by taxonomy
$args = array(
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'slug',
'terms' => 'design'
)
)
);
$query = new WP_Query($args);
🎯 Use Cases
# E-commerce
- Product Categories
- Product Brands
- Product Sizes
- Product Colors
# Portfolio
- Project Types
- Skills
- Technologies
# Blog
- Series
- Topics
- Difficulty Levels
# Real Estate
- Property Types
- Locations
- Status
# Education
- Courses
- Levels
- Subjects
# Taxonomy Best Practices
- Use singular/plural labels correctly
- Use hierarchical for categories
- Use non-hierarchical for tags
- Show in REST for Gutenberg
- Register before custom post types
# Display Taxonomy
the_terms($post->ID, 'portfolio_type')
wp_list_categories(array('taxonomy' => 'portfolio_type'))
💡 Taxonomy Tips
- Use hierarchical for structured categories
- Use non-hierarchical for flexible tagging
- Register before custom post types
- Use show_in_rest for Gutenberg
- Use meaningful slugs
“Custom taxonomies organize content better. Any structure, any purpose. Essential for content management.”
