Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm setting up the categories for my website and I have them like so:

Original categories order

That's it, I have children of the same name but they are not interchangeable. If that bugs you just think that they have different names.

Then I go to a post and I want to add categories to it and now the tree is completely gone and the categories order is completely messed up:

categories inside post

Why is this happening? It's not always like this, sometimes the tree shows up nicely but that behaviour is not consistent. I have seen this happening countless times on other blogs and so far I've just ignored this behaviour because I (or the web admin) could identify which category is child of which parent but this is not the case because some names are repeating. Anyway even if my categories may not be the best practise, maybe for the end user is not transparent that one category is child of another one if the tree is broken like that, right?

EDIT: This is only happening when editing a post, when I add a new one everything is fine and dandy:

enter image description here

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted
+50

Category-list uses the function wp_terms_checklist() in wp-admin/includes/template.php on row 90. The parameter "checked_ontop" is set to true. So the checked checkboxes will be on top.

This is only happening when editing a post, when I add a new one everything is fine and dandy

Thats because when you create a post, none of the categories are checked and the list will be intact, but when you saves one it will appear on the top because of the "checked_ontop is set to true".

You can prevent this by changing the parameter checked_ontop to false by adding this to your theme function.php.

function wpse_prevent_on_top_cat() {
    // Run only in admin
    if( is_admin() && add_action('wp_terms_checklist_args', 'wpse_prevent_on_top_cat') ) {
        // Change checked_ontop to false
        $args['checked_ontop'] = false;
        // Return the new parameter
        return $args;
    }
}

Or just install my simple plugin on this code: https://github.com/pontusab/WordPress-Category-List

The result:

enter image description here

share|improve this answer
    
Fantastic!!! And it's great that I don't need to hack the wordpress core por this, thank you! –  Elaine Marley Dec 27 '12 at 9:08
    
Glad i could help. But hey, you should never ever hack the core! –  Pontus Abrahamsson Dec 27 '12 at 9:15
    
Nah, I wasn't going to but I thought that would be the only solution if I wanted to change this issue, hence why I asked here! –  Elaine Marley Dec 27 '12 at 9:19
    
Why is this restricted to is_admin()? And wouldn’t it be slightly better to use is_admin() && add_action() to add the action only when you need it? –  toscho Dec 29 '12 at 11:20
    
aah, just thought it only being active in admin so i didn't want to load it in front-end. But your right i should use is_admin && add_action. –  Pontus Abrahamsson Jan 2 '13 at 9:14
add comment

I see that you have selected all the parent categories for your post. When you add a new post, the order is well maintained. But when you edit such a post, the categories associated with the post stack at the top while rest of the categories appear at the bottom. In case you have selected the parent categories, their association with the child categories get lost and that's why they don't appear properly. This behavior is by design only.

share|improve this answer
    
I was suspecting that. Seems to be like a very odd design, changing that order. Makes editing categories quite troublesome in my case. –  Elaine Marley Dec 26 '12 at 11:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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