Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with a unique taxonomy in WordPress?
Asked on Mar 02, 2026
Answer
Creating a custom post type with a unique taxonomy in WordPress involves registering both the post type and the taxonomy using WordPress functions. This is typically done in your theme's `functions.php` file or a custom plugin.
<!-- BEGIN COPY / PASTE -->
// Register Custom Post Type
function create_custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
);
register_post_type('book', $args);
}
add_action('init', 'create_custom_post_type');
// Register Custom Taxonomy
function create_custom_taxonomy() {
$args = array(
'label' => 'Genres',
'rewrite' => array('slug' => 'genre'),
'hierarchical' => true,
);
register_taxonomy('genre', 'book', $args);
}
add_action('init', 'create_custom_taxonomy');
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you have the correct capabilities set if you want to restrict access to certain user roles.
- Use the 'supports' array to define which features the custom post type should have (e.g., 'title', 'editor').
- Hierarchical taxonomies behave like categories, while non-hierarchical ones behave like tags.
- Always test your custom post types and taxonomies on a staging site before deploying to a live environment.
Recommended Links:
