So on the add post screen in wordpress there is the category checkbox div. Before you select a category for your post it shows the correct hierarchical structure as defined in the category admin screen. After selecting a category and saving the post it will put your selected category at the top of the list instead of keeping the structured layout. Is there a way to stop it from doing this?
Leave a Reply
You must be logged in to post a comment.
Yup.
Use the
add_meta_boxes_post
to add a new category metabox that preserves the structure and while you’re at it, remove the default one, like this:And here’s the callback:
The first function is responsible for swapping the metabox callback on the default
post_categories_meta_box
for our new one.The second function is basically a copy-and-paste of the original
post_categories_meta_box
callback, where I’ve modified the part that puts the selected categories on top.Seems like a lot of work for something so basic, eh?
The ‘wp_terms_checklist_args’ filter might not have been around back in August 2012 but now there’s a much easier way of making sure checked terms stay put.
This filter is called right inside the wp_terms_checklist() function and let’s you filter the arguments used to create the checklist: