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 Feb 03, 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 -->
// Register Custom Post Type
function create_custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
);
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:
- Custom post types allow you to organize and display different types of content in WordPress.
- Custom taxonomies help categorize and tag your custom post types, similar to categories and tags for posts.
- Ensure your theme supports custom post types by checking for `post_type_supports` in your theme files.
- Consider using a plugin like "Custom Post Type UI" for a user-friendly interface to create custom post types and taxonomies.
Recommended Links:
