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 05, 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 can be done by adding code to your theme's `functions.php` file or a custom plugin.
<!-- BEGIN COPY / PASTE -->
// Register Custom Post Type
function custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail'),
);
register_post_type('book', $args);
}
add_action('init', 'custom_post_type');
// Register Custom Taxonomy
function custom_taxonomy() {
$args = array(
'label' => 'Genres',
'rewrite' => array('slug' => 'genre'),
'hierarchical' => true,
);
register_taxonomy('genre', 'book', $args);
}
add_action('init', 'custom_taxonomy');
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you back up your site before making changes to `functions.php` or creating a custom plugin.
- Use the 'init' action hook to register post types and taxonomies to ensure they are available when WordPress initializes.
- Consider using a plugin like Custom Post Type UI for a user-friendly interface to create custom post types and taxonomies without coding.
Recommended Links:
