Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 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.

share|improve this answer
    
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 '13 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 '13 at 16:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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