Creating pre-defined taxonomies in WordPress


Staff member
I’m creating a WordPress plugin, that in turn creates a custom post type for MMA fighters. I want to organise fighters by weight class, so though this would be a good use of a custom taxonomy.

I’ve created a weight class taxonomy like this:

register_taxonomy('mma_weight_class', 'mma_fighter', array(
    'hierarchical' => false,
    'label' => __('Weight Class'),
    'query_var' => true,
    'rewrite' => true

However, this doesn’t seem to yield quite what I want. When I go to add/edit a fighter post, there’s a weight class panel that displays like the following:

<img src=" " alt="enter image description here">

What I’d like instead is a weight class panel like that, but with options (i.e. Lightweight, Middleweight, Heavyweight etc) predefined by my plugin and displayed as a drop-down list, rather than an open input as above where the user can add any ol’ option.

Is it possible to create pre-defined options for a taxonomy like this?


So, I found the <a href="" rel="nofollow noreferrer">wp_insert_term()</a> function, programmatically added the weight classes, and changed
in the taxonomy definition. This gets me closer to what I want, as I now have this:

<img src=" " alt="enter image description here">

However, I’d rather they were radios instead of checkboxes (so users could only select one weight class), and that the “+ Add New Category” option wasn’t available, as I only want users to choose from the pre-defined options and not be able to create their own.