I've got a stumper... I've created a new taxonomy called Article Type. I created four values for it, as shown in this metabox:

Article Type metabox

When I select the "Entertainment" term and update the post, something weird happens: the system creates a new term using the term_id from Entertainment in table wp_terms, see pix below:

New term created behind the scenes

enter image description here

This is clearly not the desired effect, I'm just trying to select "Entertainment".

I have no idea where to start digging into this...can anyone tell me why this is happening?

In case it matters, here's the code used to create the taxonomy:

function hhl_article_type() {
    $labels = array(
        'name'                       => _x( 'Types', 'Taxonomy General Name', 'hhl' ),
        'singular_name'              => _x( 'Type', 'Taxonomy Singular Name', 'hhl' ),
        'menu_name'                  => __( 'Article types', 'hhl' ),
        'all_items'                  => __( 'All Items', 'hhl' ),
        'parent_item'                => __( 'Parent Item', 'hhl' ),
        'parent_item_colon'          => __( 'Parent Item:', 'hhl' ),
        'new_item_name'              => __( 'New Item Name', 'hhl' ),
        'add_new_item'               => __( 'Add New Item', 'hhl' ),
        'edit_item'                  => __( 'Edit Item', 'hhl' ),
        'update_item'                => __( 'Update Item', 'hhl' ),
        'view_item'                  => __( 'View Item', 'hhl' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'hhl' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'hhl' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'hhl' ),
        'popular_items'              => __( 'Popular Items', 'hhl' ),
        'search_items'               => __( 'Search Items', 'hhl' ),
        'not_found'                  => __( 'Not Found', 'hhl' ),
        'no_terms'                   => __( 'No items', 'hhl' ),
        'items_list'                 => __( 'Items list', 'hhl' ),
        'items_list_navigation'      => __( 'Items list navigation', 'hhl' ),
    $rewrite = array(
        'slug'                       => 'type',
        'with_front'                 => true,
        'hierarchical'               => false,
    $args = array(
        'labels'              => $labels,
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_admin_column'   => true,
        'show_in_nav_menus'   => true,
        'show_tagcloud'       => false,
        'rewrite'             => $rewrite,
        'show_in_rest'        => false,
        'meta_box_cb'         => 'post_categories_meta_box',
    register_taxonomy( 'article_type', array( 'post' ), $args );
add_action( 'init', 'hhl_article_type', 0 );
  • 1
    Your taxonomy is non-hierarchical, but you have used the callback for hierarchical taxonomies.
    – Milo
    Dec 7 '18 at 3:35
  • Milo what does that mean in laymen terms?
    – Pete
    Dec 7 '18 at 5:45
  • The meta_box_cb argument is incorrect, read the description for that parameter on the documentation page. Unless you are setting a specific value, it's best to remove it, along with all the other arguments that are set to default values.
    – Milo
    Dec 7 '18 at 16:11

Thanks to @Milo for the solution. I deleted all the defaults to condense the code, and then changed the 'meta_box_cb' parameter to 'post_categories_meta_box', and it did indeed give me a tag-style metabox.

As an aside, that's not exactly what I envisioned, so I ended up using CMB2's taxonomy_radio field to get what I was after (a drop-down would have worked too):

CMB2 metabox with a taxonomy_radio field

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.