Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$10
Add a post (category already defined for user)
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.
staceypruim | 08/12/12 at 8:38am
Edit
Tutorial: How to assign prize money
(3) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
08/12/12
8:46amAbdelhadi Touil says:Hi.
I think this plugin can solve your problem:
http://wordpress.org/extend/plugins/author-category/
and this one too, but the first is easier than this one:
http://wordpress.org/extend/plugins/role-scoper/
Good luck.- 08/12/12 9:18am
staceypruim says: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.
- 08/12/12 9:18am
-

Last edited:
08/12/12
1:35pmDbranes says:You can check out the discussion here and this code
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.
- 08/15/12 8:26am
Dbranes says:I just tested the code mentioned here
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.
- 08/15/12 8:26am
-

Last edited:
08/13/12
12:28amArnav Joy says: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.
This question has expired.
Current status of this question: Community pot
Please log in to add additional discourse to this page.
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
