I’d like to have a non-hierarchical custom taxonomy displayed in the add/edit posts admin screen for a custom post type. Obviously, when the custom taxonomy is non-hierarchical, the meta box that’s displayed is similar to the tags – it’s a text field with the auto-suggest.
However, I’m more interested in having a flat, non-hierarchical taxonomy display as a list of checkbox terms. In essence, I’d like it’s functionality to be the same as categories, with the exception that child terms could not be added.
Surely this is something that other developers have done, but the normal Google searches haven’t returned much for me. Apparently this was the default behavior when custom taxonomies were originally introduced in v2.8.
I’m really not looking for a plugin solution, however code examples from plugins would be fine. When developing sites for client’s it is often beneficial to allow them to see the list of pre-established terms for a certain post type. The customer should be allowed to add additional terms, just not additional child terms.
I’m not sure, if you already found a solution for this, but when I searched for a similar one yesterday, I found this tutorial on WPtuts very helpful. It uses radio buttons, but you can easily modify it to get it working with checkboxes as well.
http://wp.tutsplus.com/tutorials/creative-coding/how-to-use-radio-buttons-with-taxonomies/
Now in 2020, i’ve found the definitive and simpliest solution:
You can pass the
meta_box_cb
to change the metabox function. If you usepost_categories_meta_box
, the non-hierarchy taxonomy will use the hierarchy editor. There is an minor problem here, you still can select the parent category (but it does not set it as an parent category). You can fix this by simply hiding the select input.I got the solution (based on the tutsplus tutorial link above) that deals with actual checkboxes here to work: http://wordpress.org/support/topic/display-tag-admin-box-like-categories-without-hierarchy it ignores the “most used” tab of the metabox that the tutsplus link addresses but personally I’m keeping it simple.
Pardon my french, but why not use the built in hierarchial=true and after that hide all the Parent dropboxes by using admin css ?
I would do that:
After, up to you to hide the parent select box of the form
use hierarchy and hide the parent selects, like this:
My solution: