Custom Taxonomy tree view not showing correctly in backend

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.

Read More

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?

Related posts

Leave a Reply

1 comment

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