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.

The objective is to ensure that when editing a post, the metabox that lists a hierarchical taxonomy doesn't reorder itself upon Update to put checked items on top.

Right now, edit-form-advanced.php calls add_meta_box(), passing a callback of post_categories_meta_box, which is defined in meta-boxes.php.

post_categories_meta_box() invokes wp_terms_checklist(), leaving the checked_ontop parameter undefined. wp_terms_checklist() defaults that parameter to true, which is the root cause of all this hooplah.

Nary a filter hook to be found anywhere along the chain until we back out and discover add_meta_boxes and add_meta_boxes_{$post_type}.

The only solution I was able to come up with myself was to hook onto one of these actions, globalize $wp_meta_boxes, and replace occurrences of the post_categories_meta_box callback with a callback of my own, where I completely duplicate all of post_categories_meta_box() and simply add the parameter 'checked_ontop' => false.

Works. But fugly. This seems ridiculous - is there no more elegant way to simply let your hierarchical taxonomies keep their order in metaboxes?

share|improve this question

1 Answer 1

There's a plugin written specifically to fix this 'feature' of WordPress, it's called Category Checklist Tree. Despite the name, it works on custom taxonomies too.

share|improve this answer
    
Scribu's plugin, as Admirable as it is, does exactly the same thing: it duplicates the entire function, and then modifies the argument, As I described. I probably was not as clear in my original post as I should have been: the request was to find a more elegant way of achieving the objective, not for a plug-in that would help me do it, since I had already rolled my own code to accomplish that. But thanks for the link to this plug-in! There is a ton of good stuff in there: I always learn something new when I read through Scribu's code. –  Tom Auger Mar 21 '12 at 23:36
    
Your way (and scribu's) is the way to do it. It's not fugly, it's just how it is. That's why the WP core uses its own API (ala add_meta_box): so you can replace its functionality with your own. The alternative is probably an even uglier javascript hack. –  chrisguitarguy Jul 6 '12 at 1:09

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.