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

Add a post (category already defined for user) WordPress

I have a wordpress site that is for serveral painting classes. Each class has a category in the blog and they post their work there and review each others. It is within a membership site and the menu options they have available to them allow them to see each class and assignment, view the class blog or post to the blog. The view is simply acheived by viewing a category page (the category within the blog for that course).

I need these people to be able to post, but only to that category within the blog. So I want to send them to the Add a Post page and have it not show the category selection area (already done). It is stripped to allow post content, and image insertion and that's about it.

When I use the code I have, it works often, but it doesn't work for all users, and I can't figure out why.

here is what I have put in the link they select to add a post:

"http://www.theimaginaryrealm.com/wp-admin/post-new.php?category_name=ITT+Paris/"


Where "ITT Paris" is the Category.

Can anyone help by either telling me why this works some of the time and not others

OR

Giving me a different way other than passing the category name in a link that might be more solid?

Thanks.

Answers (3)

2012-08-12

Abdelhadi Touil answers:

Hi.
I think this plugin can solve your problem:

[[LINK href="http://wordpress.org/extend/plugins/author-category/"]]http://wordpress.org/extend/plugins/author-category/[[/LINK]]

and this one too, but the first is easier than this one:

[[LINK href="http://wordpress.org/extend/plugins/role-scoper/"]]http://wordpress.org/extend/plugins/role-scoper/[[/LINK]]

Good luck.


staceypruim comments:

This is great if I needed each author to post to just one category. Many of the users though are registered in more than one course at a time, so I need to be able to identify multiple categories for a user.

Also, the users are often not tech savvy at all... so the website owner doesn't want them to have to think to select the category. So, I don't just want to limit their category list in the add a post screen... it has been removed from view.

I need to be able to have the action connected with a button or link text. One is on the assignments page which says "Create a blog post for this classs" and the other is one that resides on the sidebar for the blog so that while they are reading they have the option to post.

So, the solution needs to be connected to the action, if that makes sense.

Thanks so much for your time!
Stace.

2012-08-12

Dbranes answers:

You can check out the discussion [[LINK href="http://forums.whirlpool.net.au/forum-replies.cfm?t=1608032&#r7"]]here[[/LINK]] and this [[LINK href="http://pastebin.com/bGxXFRqW"]]code[[/LINK]]

This seems to be what you are looking for.

ps: if the categories are not too many, I would go with custom post types, it might be a cleaner solution, because then you can use links like:

/wp-admin/post-new.php?post_type=itt_paris
/wp-admin/post-new.php?post_type=itt_london


but then this would require changes to your template files.

Hope this helps.


Dbranes comments:

I just tested the code mentioned [[LINK href="http://forums.whirlpool.net.au/forum-replies.cfm?t=1608032&#r7"]]here[[/LINK]]

It can be called within the wp-admin like this (for logged in users):

example.com/wp-admin/edit.php?mypresetcat=13

and the following (slightly modified) code goes into the function.php:

add_action( 'admin_init', 'my_preset_category' );

function my_preset_category() {
global $user_ID;
$mycats=array(13,14); // available category id - change this
if(isset($_GET['mypresetcat'])){
$category = (int)$_GET['mypresetcat']; // get the category from the url
if(in_array($category,$mycats,TRUE)){
$post = array( // add a new post to the wordpress database
'post_status' => 'draft', // set post status to draft - we don't want the new post to appear live yet.
'post_date' => date('Y-m-d H:i:s'), // set post date to current date.
'post_author' => $user_ID, // set post author to current logged on user.
'post_type' => 'post', // set post type to post.
'post_category' => array($category), // set category to the category/categories parsed in your previous array
'post_title' => 'Title'
);
$insert_post = wp_insert_post($post); // insert the post into the wp db
$post_details = get_post($insert_post); // get all the post details from new post
$post_id = $post_details->ID; // extract the post id from the post details
$post_redirect = home_url().'/wp-admin/post.php?action=edit&post='.$post_id; // construct url for editing of post
wp_redirect($post_redirect);// redirect to edit page for new post.
exit;
}
}
}


ps:
This code is just a barebone proof of concept.
Extra security checks are needed.
The answer time is almost up, so I just post it like this ;-)

Mabye this will give you the idea.

2012-08-13

Arnav Joy answers:

I tried this

http://www.theimaginaryrealm.com/wp-admin/post-new.php?category_name=ITT+Paris/

but it requires username and password to access the page.