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 unique taxonomy in WordPress?
Asked on Mar 16, 2026
Answer
Creating a custom post type with its own unique taxonomy in WordPress involves using the `register_post_type` and `register_taxonomy` functions. This allows you to organize content beyond the default posts and pages.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'supports' => array('title', 'editor', 'thumbnail'),
);
register_post_type('book', $args);
$taxonomy_args = array(
'label' => 'Genres',
'rewrite' => array('slug' => 'genre'),
'hierarchical' => true,
);
register_taxonomy('genre', 'book', $taxonomy_args);
}
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.
- The `register_post_type` function creates a new post type called "Books".
- The `register_taxonomy` function creates a taxonomy called "Genres" associated with the "Books" post type.
- Ensure that permalinks are refreshed by visiting Settings → Permalinks after adding the code.
Recommended Links:
