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 1


First 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.