How can I create a custom post type with specific taxonomies?
Asked on Oct 14, 2025
Answer
Creating a custom post type with specific taxonomies in WordPress involves using the `register_post_type` and `register_taxonomy` 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
$args = array(
'label' => 'Books',
'public' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
);
register_post_type('book', $args);
// Register Custom Taxonomy
$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:
- Custom post types allow you to organize and display content differently from standard posts and pages.
- Taxonomies like categories or tags can be customized to fit the content type, such as "Genres" for "Books".
- Ensure your theme supports the custom post type by adding appropriate templates if needed.
- Use the WordPress dashboard under "Settings" to manage permalinks for your custom post types and taxonomies.
Recommended Links: