Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with specific taxonomies in WordPress?
Asked on Dec 28, 2025
Answer
Creating a custom post type with specific taxonomies in WordPress involves using the `register_post_type` and `register_taxonomy` functions. This allows you to define custom content types and organize them with categories or tags.
<!-- 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:
- Place the code in your theme's `functions.php` file or a custom plugin.
- Ensure that permalinks are refreshed by visiting Settings → Permalinks after adding the code.
- Custom post types and taxonomies will appear in the WordPress admin menu for easy management.
- Modify the `supports` array to include other features like 'comments' or 'custom-fields' if needed.
Recommended Links:
