I registered a non-hierarchical custom taxonomy (‘property_features’).
There is a checkbox for every terms of this tax in a custom meta box on the edit-screen.
All terms are displayed and all terms wich are attached to the post are checked correctly.

So far so good…

… but when I check one of the unchecked boxes and hit save wordpress creates a new term.

EXAMPLE:

code of unchecked checkbox I want to see checked after saving

<li id="property_features-11">
  <label class="selectit">
    <input value="11" name="tax_input[property_features][]" id="in-property_features-11" type="checkbox"> Term-Name
  </label>
</li>

code of resulting checkobx:

<li id="property_features-55" class="popular-category">
  <label class="selectit">
    <input value="55" name="tax_input[property_features][]" id="in-property_features-55" checked="checked" type="checkbox"> 11
  </label>
</li>

code I use to create the checkboxes:

function display_property_features_meta_box($post) {

    $tax_name="property_features";
    $taxonomy = get_taxonomy($tax_name);
    $args     = array(
        'descendants_and_self'  => 0,
        'selected_cats'         => false,
        'popular_cats'          => false,
        'walker'                => null,
        'taxonomy'              => $tax_name,
    );

    ?>
    <div class="tagsdiv" id="tagsdiv-<?php echo $tax_name; ?>">


        <?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?>
        <div class="tagchecklist">

            <?php
            ?>
            <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name?>" class="tagschecklist form-no-clear">
                <?php wp_terms_checklist($post->ID, $args ) ?>
            </ul>

        </div>
        <?php endif; ?>


    </div>
    <?php
}

When I change to

‘hierarchical’ => true

in the register_taxonomy args everything works fine.

3 Answers
3

This seems to be a core bug, spotted at 4.5 as well. Although documentation implies otherwise, you can not select in practice terms of non hierarchical taxonomies with the “checkoxed” metabox, the only working option is the “tag” style metabox.

Leave a Reply

Your email address will not be published. Required fields are marked *