Categories lose hierarchy order once assigned to post

I setup some hierarchical categories and when I assign them to a post the widget reflows and loses the hierarchy display. Example:

- Education Services
-- Arts & Archives
--- Fine Arts
-- Reference
-- Health Sciences

When selecting “Education Services” & “Reference” (marked with ‘x’) the widget appears like this:

Read More
x Education Services
-x Reference
- Arts & Archives
-- Fine Arts
- Health Sciences

So since the selected (top-level) parent goes to the top, all children besides the selected one look they have lost their parent (even though they actually have not).

I have read some other forums post/support tickets but not much about this issue. Any suggestions?

Related posts

Leave a Reply

3 comments

  1. Based on the plugins Category Checklist Tree and Categories in Hierarchical Order, you could directly use this filter in your function.php file without adding any plugin:

    add_filter('wp_terms_checklist_args', function($args, $idPost) {
        $args['checked_ontop'] = false;
    
        return $args;
    }, 10, 2);
    

    It is also possible to apply this filter only to a specific taxonomies:

    add_filter('wp_terms_checklist_args', function($args, $idPost) {
        $taxonomies = ['foo', 'bar'];
    
        if (isset($args['taxonomy']) && in_array($args['taxonomy'], $taxonomies)) {
            $args['checked_ontop'] = false;
        }
    
        return $args;
    }, 10, 2);