WordPress Q&As Logo
WordPress Q&As Part of the Q&A Network
Q&A Logo

How can I create a custom post type with its own taxonomy?

Asked on Oct 21, 2025

Answer

Creating a custom post type with its own taxonomy in WordPress involves using the `register_post_type` and `register_taxonomy` functions. This allows you to organize content beyond the default posts and pages.
<!-- 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',
        'public'       => true,
        'hierarchical' => true,
      );
      register_taxonomy('genre', 'book', $taxonomy_args);
    }
    add_action('init', 'my_custom_post_type');
    <!-- END COPY / PASTE -->
Additional Comment:
  • Place the code in your theme's `functions.php` file or in a custom plugin.
  • Adjust the labels and arguments to fit your specific needs.
  • Ensure that permalinks are refreshed by visiting Settings → Permalinks in the WordPress dashboard after adding the code.
✅ Answered with WordPress best practices.

← Back to All Questions
The Q&A Network