When creating a custom taxonomy in WordPress, you get a different default interface for hierarchical taxonomies than for non-hierarchical taxonomies. Hierarchical taxonomies get a checkbox-based interface, like Categories, while non-hierarchical taxonomies get an auto-complete interface, like Tags.
You can select the metabox interface used with the ‘meta_box_cb’ attribute of the ‘register_taxonomy’ call. By default, hierarchical taxonomies use the callback ‘post_categories_meta_box’ and non-hierarchical taxonomies use the callback ‘post_tags_metabox’. Unfortunately, the two options aren’t compatible with each other.
For some reason, when a post is saved or updated, non-hierarchical taxonomies expect to receive an array or comma-separated list of term names (as strings), while hierarchical taxonomies expect to receive an array of term ids (as ints). Luckily, it is fairly trivial to translate between the two formats.
Here’s the code to make a non-hierarchical taxonomy that uses the category-style metabox:
wordpress taxonomy says:
Excellent tutorial! This is really helpful to used my business site development.
Thanks.
acuabit says:
Hi.
Know you some plugin to do default post category interface like labels (with autocomplete)?
Thanks.
Steve says:
Hello, I am trying to do this very thing and everything looks right, however after selecting a few terms from my custom taxonomy and clicking the Update button to save, all terms in that taxonomy are cleared completely and not saved to the post. Any thoughts? Does this solution still work? Thanks!