It seems to me that if use a CPT and would use it with only one category, you don’t need the category at all. site.com/cpt-slug/ will return the same thing as the category.
Thanks.
Yes, you’re right, and there’s other info which I should have mentioned…
I currently have the slug set as ‘magazine’, so the url path is /magazine/item-name/ and hence works as you suggest.
The reason for assigning a category is for use with a third-party membership script, for which assigning a category (magazine) to be protected is a better option than setting protection on individual pages.
By having a category of ‘magazine’, to which I can assign (currently done automatically) all ‘item’ posts, I’m thus still able to show an unprotected ‘teaser’ page (ordinary, not cpt, page) at an url of /magazine/.
Having initially struggled to comprehend CPTs, I’ve subsequently been lazy and not revisited to understand the whole taxonomy thing – hence my post… I don’t know if registering a taxonomy of ‘magazine’ will add such a check-box to the category metabox and whether it’ll be available for just CPTs or also ordinary posts.
I really should be more self-responsible and dive-in rather than hesitating.
I’d use a custom taxonomy to keep things separate from posts. If you add a custom taxonomy and set it to be part of the CPT in the CPT’s definition, you’ll get a metabox on the CPT add/update page.
Thanks.
Having experimented, I think I understand this better – but there’s still some issue which puzzle me.
I can stop the normal/post categories metabox appearing on the edit screen for the ‘item’ cpt by not using:
'taxonomies' => array( 'post_tag', 'category' ).
And I’ve added a taxonomy which adds a menu item and metabox for the ‘item’ cpt, using:
function build_taxonomies() {
register_taxonomy( 'categories', 'item', array( 'hierarchical' => true, 'label' => 'Special Categories', 'query_var' => true, 'rewrite' => true ) );
}
But if I then create a new category using that ‘item’ metabox, the category also appears in the metabox of normal posts. I guess I’m missing something which would stop this.
change the line to
‘taxonomies’ => array( ‘your_new_taxonomy’ )`
Thanks.
This initially caused a duplicate category issue, which I began to describe before realising the cause was that the code I use to auto-assign ‘item’ CPTs to ‘magazine’ category is probably creating the duplicates.
Removing it seems to sort the issue. So now I need to find a way to auto-assign without creating duplicate categories.
function assign_item_category_automatically($post_ID) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
wp_set_object_terms( $post_ID, 'magazine', 'category');
}
}
add_action('publish_item', 'assign_item_category_automatically');