0

I've got a custom post type called "Resources".

How I've defined the taxonomy:

register_taxonomy(  
    'resource',  // the name of the taxonomy
    'resources', // post type name
    array(  
        'hierarchical' => true,  
        //'label' => 'Resources',  // display name
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'resources', // This controls the base slug that will display before each term
            'with_front' => false // Don't display the category base before 
        )
    )  
);  

How I've registered the post type:

register_post_type(
            'resources',
            tp_build_post_args(
                'resources', 'Resource', 'Resources',
                array(
                    'menu_icon'     => 'dashicons-welcome-write-blog',
                    'menu_position' => 20,
                    'has_archive'   => true,
                    'public'      => true,
                    'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
                    'taxonomies' => array('post_tag', 'type', 'sector')
                )
            )
        );

As you can see, I do not have the category option selected in 'taxonomies' => array('post_tag', 'type', 'sector'), but it is appearing as an option in the admin:

enter image description here

Why is this?

0
1

First, I believe that "Categories" is actually for the custom taxonomy resource and not the standard category taxonomy. But in the menu, it's labeled Categories because you didn't set a custom label for the resource taxonomy (because the label is commented out and defaults to Categories):

register_taxonomy(
    'resource',  // the name of the taxonomy
    'resources', // post type name
    array(
        'hierarchical' => true,
        //'label' => 'Resources',  // display name <- this
        ...
    )
);

Secondly, the resource taxonomy is actually assigned to the resources post type, despite the taxonomy is not in the list of the post type's taxonomies property:

register_taxonomy(
    'resource',  // the name of the taxonomy
    'resources', // post type name <- here, the taxonomy will be assigned to this post type
    array( ... )
);

If you don't actually want the resource taxonomy to be assigned to the resources post type, then either set the post type to null or whatever the proper post type is:

register_taxonomy(
    'resource',  // the name of the taxonomy
    null,        // set to null, which means don't assign to `resources` or any post types..
    array( ... )
);

Alternatively, you can use unregister_taxonomy_for_object_type() to un-assign the taxonomy from a post type:

// Call after the post type and taxonomy are both registered.
unregister_taxonomy_for_object_type( 'resource', 'resources' );
2
  • 1
    Hi Sally, apologies, was caught up with other stuff. But yes, you have solved my issue, wasn't aware that it defaults to "Categories" if no label is defined - thanks for the comments too! – Freddy Aug 23 '19 at 8:14
  • Glad it helped. :) And you should probably know that the default label is Categories only if the taxonomy is hierarchical; if it's not hierarchical, then the label defaults to Tags. – Sally CJ Aug 24 '19 at 14:22

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.