Question

I have a custom hierarchical taxonomy that is called 'Categories', but serves a different area of the site than the default "Categories" taxonomy. The problem I'm having is with selecting children terms in the interface while posting content. If the user selects and children terms, they move to the top of the Categories box and lose association and visual hierarchy with its parent. Here's an image showing what happens:

Checked categories are moved to the top of the list, breaking the hierarchy

I haven't set any unusual parameters that I know of, here's the register_taxonomy call:

register_taxonomy( "workshop_categories", 'workshop',
    array(
        "label" => "Categories",
        "singular_label" => "Category",
        "rewrite" => true,
        "show_ui" => "true",
        'hierarchical' => true,
        'rewrite' => array('slug' => 'category')
    )
);

Any input is appreciated!

Was it helpful?

Solution

This seems to be normal, it also happens for categories. The wp_terms_checklist(), which creates the checklist, has an argument checked_ontop, enabled by default. The metabox does not override this, so checked categories or custom terms always appear on top of the list. This does not affect their actual hierarchy, only how they are displayed there. It seems the remaining items of the hierarchy, that "lost" their parent, are added to the bottom.

I do not think there is a sensible way to override this, unless you want to duplicate the whole meta box code.

OTHER TIPS

It can be done by using this hook if anyone is still searching for the solution.

function ya_disable_popular_ontop($args) {
   //If this is your required taxonomy then disable the popular on top.
    if($args['taxonomy'] == 'YOUR-TAXONOMY'){
        $args['checked_ontop'] = false;
    }
    return $args;
}
add_filter('wp_terms_checklist_args','ya_disable_popular_ontop');

A bit late, but if anybody comes across this, it's solved with this post here: Hierarchical taxonomy UI

Not sure if I can post external links here, but I've just solved this for custom taxonomies or WordPress internal categories.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top