14

I have registered a custom tax to my CPT. On the edit screen the tax meta box appears with an autocomplete field.

Is it possible to display it as checkboxes or dropdown instead?

3 Answers 3

21

You probably did not set the 'hierarchical' argument to true in your register_taxonomy. This would mean that it defaults to false, which gives you a tag-like interface.

Add 'hierarchical' => true to your register_taxonomy.

5
  • Oh yeah... Thanks! BUT Would it now possible to change it to checkbox or even select? I want to be able to put this as setting into my plugins settings. Aug 7, 2013 at 17:51
  • 1
    Changing hierarchical to true should change the interface to checkboxes on your edit screen for the CPT.
    – vancoder
    Aug 7, 2013 at 18:06
  • Yes, it does – but I want to be able to switch between these options. I don't think that it is good practice to switch between hierarchal and not. It does not change ONLY the interface, am I right? Aug 7, 2013 at 18:09
  • Well, hierarchical makes it... hierarchical :) You cannot switch between the 2 interfaces to my knowledge.
    – vancoder
    Aug 7, 2013 at 18:33
  • This solution doesn't create a checkbox or drop down menu.
    – Dev
    Sep 12, 2017 at 9:28
20

As of WP 3.7 (https://core.trac.wordpress.org/ticket/14206) you can add this argument to register_taxonomy:

'meta_box_cb' => 'post_categories_meta_box'

to get the built-in checkbox category style metabox without having to make your taxonomy hierarchical.

Also you could instead provide your own callback function to create your own metabox (i.e. with a dropdown).

7
  • 1
    Great, this is exactly what I needed without having to make the taxonomy hierarchical. Thanks Dec 29, 2016 at 21:20
  • The issue with this is that the non-hierarchical and hierarchical taxonomies have a different data structure that needs to be saved. For how to fix this issue see here gist.github.com/gschoppe/… Feb 27, 2017 at 6:18
  • This solution doesn't create a checkbox or drop down menu.
    – Dev
    Sep 12, 2017 at 9:28
  • 1
    This is huge! Thank you... I never knew it existed Feb 10, 2019 at 20:00
  • Where do I change the information as suggested by Justin Fowell? Sorry if this is very obvious for all, I am just learning. Emily Jun 23, 2021 at 11:43
-1

if you want to change the term of existing plugin to checkbox you need to edit the existing register_taxonomy().

add_action( 'init', 'change_room_term_to_checkbox', 999);
function change_room_term_to_checkbox()
{
    $tax = get_taxonomy('roomtype');
    $tax->meta_box_cb = 'post_categories_meta_box';
    $tax->hierarchical = true;
}

'roomtype' is the name of term used on register_taxonomy('roomtype', array(.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.