X

Add category selection to custom post type

Adding this wordpress snippet to the functions.php will enable category selection within the editor for your custom post type. Don't forget to change the CUSTOM_POST_TYPE to the name of the custom post type you created.


function reg_cat() {
         register_taxonomy_for_object_type('category','CUSTOM_POST_TYPE');
}
add_action('init', 'reg_cat');

Comments  Leave a Reply

  1. 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.

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

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

    Thanks 

  4. 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.

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

    La bamba!

    1. Cool glad you like the snippet, also check out add tag selection.
      http://wpsnipp.com/index.php/functions-php/add-tag-selection-to-custom-post-type/

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!