Ask any question about WordPress here... and get an instant response.
How can I create a custom post type with its own taxonomy?
Asked on Nov 30, 2025
Answer
Creating a custom post type with its own taxonomy in WordPress involves using the `register_post_type` and `register_taxonomy` functions. This allows you to organize content into distinct types and categories beyond the default posts and pages.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
// Register the custom post type
register_post_type('book', array(
'labels' => array(
'name' => __('Books'),
'singular_name' => __('Book')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
'supports' => array('title', 'editor', 'thumbnail')
));
// Register the custom taxonomy
register_taxonomy('genre', 'book', array(
'labels' => array(
'name' => __('Genres'),
'singular_name' => __('Genre')
),
'hierarchical' => true,
'rewrite' => array('slug' => 'genres')
));
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Place this code in your theme's `functions.php` file or a custom plugin.
- Adjust the labels and settings to suit your content needs.
- Ensure permalinks are refreshed by visiting Settings → Permalinks after adding the code.
- Custom post types and taxonomies can be managed in the WordPress dashboard under their respective new menu items.
Recommended Links:
