0
$args = array(
        'labels'             => $labels,
        'description'        => __( 'The Video Custom Post Type', 'xxxx' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'videos' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
        'taxonomies'         => array( 'category' ),
    );

This is how I gave the category functionality to one of my custom post type, but it also has the same categories coming up that are present in the default post type when we browse like this:

Videos >> categories

In short, categories are equally present for both the default and CPT. Is it normal or there is something wrong?

5

Because Category is a specific taxonomy, not just a piece of general 'functionality' that you can add to post types.

When you add category to taxonomies for your post type you're registering the Category taxonomy that already exists for Posts for your post type.

If you want to have separate Categories for your post type you need to register a custom taxonomy with register_taxonomy(). Something like video_category.

1
1

In Your arguments you give default taxonomies name. Like:

'taxonomies' => array( 'category' ), 

Here you pass the your custom taxonomies slug name. Like:

'taxonomies' => array( 'custom-taxonomies-slug' ),

So first you create custom taxonomies where you create your custom post-type

Reference: https://codex.wordpress.org/Function_Reference/register_taxonomy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.