Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with its own taxonomy in WordPress?
Asked on Apr 09, 2026
Answer
Creating a custom post type with its own 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 -->
function my_custom_post_type() {
// Register 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 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:
- Ensure you use unique slugs for your post type and taxonomy to avoid conflicts with existing content.
- After adding the code, visit "Settings → Permalinks" in your WordPress dashboard and click "Save Changes" to flush rewrite rules.
- Consider using a child theme or a custom plugin to keep your changes separate from the main theme files.
Recommended Links:
