最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - Category tree is flattened inside admin upon saving

matteradmin6PV0评论

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.

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.

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.

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.

Share Improve this question asked Jan 3, 2017 at 14:05 powerbuoypowerbuoy 8421 gold badge7 silver badges15 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

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

The plugin can be resumed to this simple code:

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

comment list (0)

  1. No comments so far