How can I force the user to first choose a category before continuing to the editor when creating a new post? I want to set some default content, but this is based on the category, so I need to know that before showing the editor (unless I do some fancy Ajax stuff, but in this case I don’t want to do that).
Leave a Reply
You must be logged in to post a comment.
I solved this by hooking into
post-new.php
, and checking for acategory_id
request parameter. If it does not exist, I display a form with a category dropdown that submits back to this page, and then callexit()
so the regular post form does not display. If it exists, I set up a hook forwp_insert_post
that will add the category. This works because a new post is already created in the database via theget_default_post_to_edit()
function, and we can add categories, tags, or other (meta) content. The form is rendered after this with the “fresh” new content.