Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with taxonomies in WordPress?
Asked on Jan 16, 2026
Answer
Creating a custom post type with taxonomies in WordPress involves registering both the post type and the taxonomies using WordPress functions. This can be done by adding code to 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 create new content types, such as "Books" in this example.
- Taxonomies like "Genres" help categorize and organize these custom post types.
- Ensure you flush rewrite rules after adding new post types or taxonomies by visiting the "Permalinks" settings in the dashboard.
- Consider using a child theme or a custom plugin to avoid losing changes during theme updates.
Recommended Links:
