3

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

2

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.

0

If you use categories ( hierarchical = true ) then you should work with term_id:

<input value="{{WP_Term->term_id}}"

If you use tags ( hierarchical = false ) then you should work with name:

<input value="{{WP_Term->name}}"
-1

When I change to 'hierarchical' => true in the register_taxonomy args everything works fine.

This implies that normally you have this set to false. If hierarchical is set to false, then you have tags, not terms, which is probably causing the issue.

2
  • So I have a general misunderstandig of what terms are. I thought terms are the "items" of a taxonomy no matter if hierarchical or not? I´ll do some research tomorrow. Thanks for the hint.
    – LichtAnd
    Apr 2, 2013 at 23:09
  • Hmm I didn´t find any clue that there is a difference between hierarchical taxonomies like categories and non-hierarchical ones like tags despite the fact that hierarchical ones can have parents and childreen. I can also use any term-related native wp method with my non-hierarchical custom taxonomy and I do always get the expected result.
    – LichtAnd
    Apr 3, 2013 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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