Set a checkmark in a category based on a URL-parameter

I’ve made a site, where there’s a category for each page. And now I’m trying to make it so, that if you on that given page press ‘Create post’, that it then sends a parameter to the URL, as such:

example.org/wp-admin/post-new.php?post_type=CPT&category=3

And it doesn’t need to actually put the post in the category… It just needs to set the checkmark in the category with ID=3, so when it’s posted, that it then does it then.

I imagined hooking onto something along the lines of ‘create_post’ or something like that and just do it with some JavaScript (find #categorydiv and .inside, and find the category by ID and mark it as checked). But it feels a bit ‘hacky’ to me.

Is it really the right way to do it, – or does WordPress offer a better way?

Read more here:: Set a checkmark in a category based on a URL-parameter

Leave a Reply

Your email address will not be published. Required fields are marked *