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.
Instructions:
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() { register_taxonomy_for_object_type('category','CUSTOM_POST_TYPE'); } 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.
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.
Extremely helpful (in my hour of need!)
Thanks so much for sharing 🙂
Thanks
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’)
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.
La bamba!
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/