Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Create a "add new post" (or item) link with category selected? WordPress


I'm trying to create a link that if a user clicks it goes to the add new post page with a category already selected.

I'm using custom post types

I currently have:

That works fine on picking with custom post type to go to but I can't figure how the paramater to make a category already selected when they go to the page.

I tried "" & "" but they don't seem to work.

Can someone help me figure out a way that I can just create a link that will pass the parameter to make a category already selected?

Answers (2)


Luis Abarca answers:

You can add the selected category on save_post action, i answer a similar question before here [[LINK href=""]][[/LINK]]

You can pass the category via URL, add to a hidden field and then on save_post add that category to he post.

Zach Reed comments:

I don't really follow? Can you give some example code for my case?

Luis Abarca comments:

The other way is check the category with jQuery.

Get the category ID via $_GET.

add_action('admin_footer', 'my_admin_footer');

function my_admin_footer()
$('#in-category-<?php echo $_GET['post_category'] ?>').attr('checked', true);

Luis Abarca comments:

With jQuery, the category is visually selected, i think is more what you need.

you can also take that code, put it in a .js file and add it with:

Zach Reed comments:

That worked perfectly! Thanks! :)


Luis Cordova answers:

hmm no you need to use proper hooks for this, where do you want it can you email me at cordoval at

Zach Reed comments:

I am making it a link on the front-end of the site. I want the user to be able to click the link and go straight to the "add new" post page (for that specific post type) and already have a category selected when they get there so they don't have to check that box.

I already figured out how to pass the post type parameter like you see above, I just can't get it to pass a category.

Luis Cordova comments:

have you tried extracting the category into the request variable? and passing it over like that?

that is standard in php right?

Zach Reed comments:

I'm not sure I know how to do that? Can you provide an example?