I have created a user role vendor
. Right now i am able to give the capabilities to the users, to be able to only edit,delete etc
But then the user sees all the posts irrespective of who is the owner of the post.
But I was wondering can i somehow add capability to rolevendor
so that user is only able to see his posts only...
I have created a user role vendor
. Right now i am able to give the capabilities to the users, to be able to only edit,delete etc
But then the user sees all the posts irrespective of who is the owner of the post.
But I was wondering can i somehow add capability to rolevendor
so that user is only able to see his posts only...
1 Answer
Reset to default 1First of all you need to remove capability edit_others_posts
if assigned to vendor role.
Then use the code snippet given below:
function posts_for_current_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( 'edit_others_posts' ) ) {
global $user_ID;
$query->set('author', $user_ID );
}
return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
Above code allows any users with the capability to edit other’s posts to view all posts. Where as users having role Vendor will only see their own posts.
For more customization you can use 'User Role Editor' plugin.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745360798a4624347.html
评论列表(0条)