How to Add Categories and Post Tags to WordPress Custom Post Type

If you created a custom post type in WordPress and couldn’t find the categories and post tags taxonomies, do not fret because the solution is easy.

To add categories and post tags to a custom post type, include the taxonomies argument to register_post_type().


function post_type_init() {
    $args = array(
      'public' => true,
      'label'  => 'Demos',
      'taxonomies' => array('category', 'post_tag') // The real deal
    );
    register_post_type( 'demo', $args );
}
add_action( 'init', 'post_type_init' );

Alternatively, use the register_taxonomy_for_object_type() function like so:


add_action('init', 'demo_taxonomies');

function demo_taxonomies() {
 register_taxonomy_for_object_type('category', 'demo');
 register_taxonomy_for_object_type('post_tag', 'demo');
}
Don’t miss out!
Subscribe to My Newsletter
Invalid email address