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:
Why is this?
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:
Why is this?
Share Improve this question asked Aug 21, 2019 at 13:48 FreddyFreddy 1771 silver badge12 bronze badges 01 Answer
Reset to default 3First, 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' );