Create category only for custom post type

I would say that you need to also create a custom taxonomy if you want it to be limited to the one post type. “Categories” is already connected to posts by default.

From the WordPress Codex

function people_init() {
    // create a new taxonomy
    register_taxonomy(
        'people',
        'post',
        array(
            'label' => __( 'People' ),
            'rewrite' => array( 'slug' => 'person' ),
            'capabilities' => array(
                'assign_terms' => 'edit_guides',
                'edit_terms' => 'publish_guides'
            )
        )
    );
}
add_action( 'init', 'people_init' );

So, if you called it “team-category”, you would then use that in the ‘taxonomies’ array in your post type.

Here’s a more specific example:

function tr_create_my_taxonomy() {

    register_taxonomy(
        'team-category',
        'team',
        array(
            'label' => __( 'Category' ),
            'rewrite' => array( 'slug' => 'team-category' ),
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'tr_create_my_taxonomy' );

Leave a Comment