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'm using a Custom Post Type product with the Custom Taxonomy product_category. When editing a product in WordPress, there is a problem with displaying the product categories tree view right.

When an item is checked, it will move to the top of the list. When this item is a top level category, the child categories stay in the same spot in the list and therefore aren't shown correctly.

When an subcategory is selected, it will also move to the top of the list. It isn't shown in the tree view anymore.

An example:

Before selecting:
O - A
O   - A.1
O   - A.2
O   - A.3
O - B
O   - B.1
O   - B.2
O   - B.3

After selecting:
X - A.2
X - B
O - A
O   - A.1
O   - A.3
O - B.1
O - B.2
O - B.3

O = unchecked
X = checked

I thinks it's a WordPress bug but I can't find the problem in the WordPress core files. Does anyone know a solution?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Found a solution. It is a WordPress builtin functionality, not a bug. Could be prevented with the 'wp_terms_checklist_args' filter.

Below an example for use with Custom Post Type 'product' and Custom Taxonomy 'product_category':

add_filter( 'wp_terms_checklist_args', 'checked_not_ontop', 1, 2 );

function checked_not_ontop( $args, $post_id ) {
    if ( 'product' == get_post_type( $post_id ) && $args['taxonomy'] == 'product_category' )
        $args['checked_ontop'] = false;

    return $args;
}

http://core.trac.wordpress.org/ticket/10982
http://core.trac.wordpress.org/ticket/20054

share|improve this answer

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.