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 Dec 23, 2025
Answer
Creating a custom post type with its own taxonomy in WordPress allows you to organize content beyond the default posts and pages. This involves registering the post type and taxonomy using WordPress functions.
<!-- 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:
- Place the code in your theme's functions.php file or in a custom plugin.
- Adjust the labels and arguments 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 names.
Recommended Links:
