Better way to enforce category hierarchy in post_categories_metabox?
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.
add_meta_box(), passing a callback of
post_categories_meta_box, which is defined in
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
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?