1

Is there a way to avoid WordPress "flattening" the category tree when a child category is selected?

This applies to both custom taxonomies and WP's built in "category" taxonomy.

To explain further, say I have the following category tree:

Parent
    Child
        Grandchild
Another parent
    Another child
    Another child
A third parent

If I then select "Grandchild" as my category, the tree will now look like this upon saving:

Grandchild
Parent
    Child
Another parent
    Another child
    Another child
A third parent

This makes it very hard for authors to remember which grandchild belongs to which parent and imo makes absolutely zero sense. I guess one reason for this might be so that the selected category is always in the top of the list, but I would very much like to disable this behaviour.

Also see attached image.

Flattened Categories

Please note that this is not theme or plugin-related. I tried this with a completely fresh WP-install with zero plugins and the default theme.

2 Answers 2

2

I haven't fully tested this, but it may be helpful: Categories in Hierarchical Order plugin at https://wordpress.org/plugins/categories-in-hierarchical-order/

2
  • Perfect, thanks! I tried Googling myself first of course, but I guess I phrased my query poorly because I couldn't find a thing.
    – powerbuoy
    Commented Jan 3, 2017 at 15:50
  • This plugin works well, thank you! With issues like this it is difficult to know what to search for. I searched for 'category moves from parent on save wordpress'.
    – Davey
    Commented Jul 14, 2017 at 8:52
5

The plugin can be resumed to this simple code:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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