How to Add Category Selection to Custom Post Type

Snippets by IsItWP

Are you looking for a way to add category selection to custom post type? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add category selection to custom post type in WordPress.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function reg_cat() {
add_action('init', 'reg_cat');

Don’t forget to change the CUSTOM_POST_TYPE to the name of the custom post type you created.

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 43 simple WordPress themes to start a website and how to create a guest post submission form in WordPress.

Comments  Leave a Reply

  1. Iheruamdu Calistus Eberechukwu March 4, 2020 at 9:41 am

    Extremely helpful. Thanks

  2. Doesn’t work

    1. Hi Nat,
      Be sure to change the CUSTOM_POST_TYPE to the name of the custom post type that you made.

  3. It would be cool if you talked about how and why you implemented this approach. As a developer, I like to understand the ‘why’ behind the solution.

    1. The register_taxonomy_for_object_type() function is used because it adds taxonomies to post types.

      1. Does this work for custom post types and custom taxonomies? For the default taxonomy with custom post type, it is working, but not for custom taxonomy.

        1. Yes, register_taxonomy_for_object_type() should work for any registered taxonomy. If it doesn’t work, you may want to check if the taxonomy has been registered properly.

  4. Hey there, Thanks for this info. I would like to add categories to my woocommerce products to further structure data and pull products into some category based widgets (i realise products have a “product category” already) Can you tell me what the code should read for Woocommerce custom post product types. I am unsure how to find this out.

  5. Extremely helpful (in my hour of need!)
    Thanks so much for sharing 🙂

  6. Mohamed Ramadan March 19, 2012 at 5:19 am


  7. Adedoyin Kassem April 11, 2011 at 3:20 pm

    Nice approach, but i do think instead of writing this somewhat “much” code, the theme developer should just add this line below into the register_post_type function.

    ‘taxonomies’ => array(‘category’)

    1. Hi Adedoyin
      Yes this is very true, this is just another method to add taxonomies however I have used this method to limit access to taxonomies editing based on role.

  8. Alexandre Klostermann April 5, 2011 at 8:25 pm

    La bamba!

    1. Cool glad you like the snippet, also check out add tag selection.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!