Once I have a CPT and a custom taxonomy, I can see two ways of adding the taxonomy to the CPT:
1) Edit the CPT and go to the taxonomy tab, select it and save. Or go to the Post types tab and select the CPT and save. These do the same thing.
2) In the CPT add a taxonomy field and choose the taxonomy.
Are these two ways doing exactly the same thing except that for 1) the taxonomy appears in the right sidebar when editing a CPT post and also the custom taxonomy appears within the associated CPT menu in the admin sidebar? Or is there a difference between the two in how taxonomy values are stored and therefore queried?
The only benefit I can see from doing only 2) is that I can hide the taxonomy in the right sidebar. Is this correct?
Is there any harm in doing both 1) and 2)? I've tried this and can see that both are updated with the selected taxonomy values when I save.
1. Edit the CPT and go to the taxonomy tab, select it and save. Or go to the Post types tab and select the CPT and save. These do the same thing.
In fact, you need to assign the post type and taxonomy when editing the post type and taxonomy also. Please read more on the WordPress documentation https://developer.wordpress.org/reference/functions/register_post_type/#taxonomies
When registering a post type, always register your taxonomies using the taxonomies argument. If you do not, the taxonomies and post type will not be recognized as connected when using filters such as parse_query or pre_get_posts. This can lead to unexpected results and failures. Even if you register a taxonomy while creating the post type, you must still explicitly register and define the taxonomy using register_taxonomy().
2. In the CPT add a taxonomy field and choose the taxonomy.
Yes, the custom field
taxonomy of Meta Box support setting post terms like the standard taxonomy box of WordPress. There is one note, you can only use one of two on the same page. If you set two categories for the post in different boxes, only one can work.
Please read more on the documentation https://docs.metabox.io/fields/taxonomy/
Thanks Peter. I'm using the Metabox Builder so no need to register with code and I only have the one taxonomy field in my CPTs.
I think I'll just create a custom field linked to the taxonomy and then hide the taxonomy control in the right side when editing post.