Skip to main content

How To Create Categories For Custom Post type

Submitted by admin on Wed, 12/08/2021 - 13:20
I have already explained how to create custom post / content type in WordPress. In this tutorial, we will learn how to create categories for our custom post type.
Let's say, we have created a new content type book. And now we want to create Subject categories for book post type. register_taxonomy() is used to register new category.
Add following codes in functions.php of your theme.

// register subjects for book
function book_taxonomy() {
    'book', // This is post type.
      'label' => __( 'Subject' ),
      'rewrite' => array( 'slug' => 'subject', 'hierarchical' => true ),
      'hierarchical' => true,
add_action( 'init', 'book_taxonomy' );

You should now get option to create Subjects for Book post type.

Hope this tutorial was helpful.
If you need help with categories for custom post type in WordPress, Please leave a comment below and I will get back to you.


Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.