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.
Related Posts:
- What action should I hook into when adding roles and capabilities?
- What’s the difference between Role and Meta capabilities; When to use map_meta_cap() filter
- Disable posts, only allow to edit existing pages, not create new ones (create_posts)
- How to get all capabilities of an existing user role
- Does the “promote_users” capability allow someone to create a new admin account?
- Add Media Upload Capabilities Needed for Custom Role for non-Posts
- How can I prevent a writer from being able to edit an article that has been scheduled?
- Check whether user can delete a given post
- Allow unfiltered HTML in titles for low level users?
- Allow users to set a post author
- Unify the roles and caps?
- Filter list of rules based on a capability
- Using author_can() on custom post types in WordPress
- How to show a admin bar menu item only to users with certain capabilities?
- Theme option editing capability problems
- Assign multiple roles , overlapping capabilities
- WordPress remove capability post ,media completely for custom role
- Is there a way of retrieving the core WP capabilities?
- Best Roles and Capability on a site with review features using a front end custom post
- Manage Roles and Capabilities on Multi-site
- add_role() run only once?
- Custom post type role permissions won’t let me read
- what’s the meaning of the field wp_capabilities in table wp_usermeta
- What is valid timing of using current_user_can() and related functions?
- Groups of capabilities: users with multiple roles?
- Allow user to “edit_others_posts” to save only, not publish
- Allow user to Edit Posts but not Add New?
- Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter
- Apply custom role capabilities to administrator (without plugin)
- Possible to make custom role in multisite that can add sites?
- How to enable the theme editor cap for an editor role?
- current_user_can( ‘edit_post’, $post_id ) does not work for contributer but for administrator
- Editor role cannot save custom theme options
- How can I prevent users from creating new categories?
- How to Structure a New Role/Capability Scheme?
- Allow user to Publish, but not Edit or Delete
- Email notification for editors only
- How to allow Unfiltered HTML in a wordpress multisite install
- Is there a simple way to manage capabilities per user?
- Author Role – Allow editing of Gallery images
- What is the difference between “create_users” and “add_users” capabilities?
- Role Capabilities: Add New Ones?
- Allow user to edit specific user with meta key using map_meta_cap
- How to remove sticky post capability for a specific user role?
- Let new user role to ‘edit_others_posts’ of other user role, not of its own type
- Custom post type capabilities require “create_posts” to access the edit posts list page
- Add custom capabilities to existing custom post type
- allow edit of custom post type but not regular posts?
- Users with custom roles can’t read each other’s comments
- add_menu_page() for more than one user role
- Why is my Custom Post Type not showing up after adding capabilities?
- Can you set a role as author?
- Allow Author on Site A capability to upload files on Site B in Multi Site
- Limit role to one plugin [duplicate]
- Custom user roles for access to specific parts of the site
- map_meta_cap woes
- Roles for Custom Post Types
- can’t see custom post content filtered under “mine” filter in admin panel
- Giving permission to anyone (non-users as well) with a password to edit a post, possible?
- Subscriber (with read permissions) cannot view Private posts
- How can I add a custom role capability to use in a custom plugin?
- “Submit for review” for updates on existing posts
- Add a role and give admin priviledges
- Usage of current_user_can()
- “edit_published_posts” and “edit_other_post” issue
- Adding post tags without capability edit_posts
- WordPress Remove Submenus
- Remove capability from specific user
- Authorize users for specific pages and/or categories
- Custom Capabilities for CPT and Problem with current_user_can()
- Which capabilities are available in Gravity Forms Salesforce plugin? [closed]
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- Select other roles as custom post authors
- WooCommerce which roles and capabilities control user login re-direct to Woo Account Page?
- What’s the correct way to add capabilites to user roles?
- User Capabilities are not available in WP REST permission callback?
- current_user_can(‘administrator’) not working in custom login
- Let editors view post in admin but not be able to perform a save/edit
- Plugin page and capabilities
- Require Capability to View Woocommerce Product
- How to query users to count all with a custom capability and limit it to a set of roles?
- User role and capablities only for 1 plugin
- How can I add capability to multiple roles?
- Create a Capability category to group a few custom Capabilities
- Custom Gutenberg Block and unfiltered_html capability
- Disabling user capability to edit_posts or delete_posts in the front-end
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- admin can not change author profile picture
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- How to add a menu page for options in wordpress for user that has the role of vendor?
- creating different edit screens for different roles
- add_role menu pages are not visible
- Users can only save their draft once before saving for revision
- Add role and edit page capabilities
- Hide user fields based off capability
- Author capabilities: Deleting comments on their own published posts
- Custom post type & role issues
- Want to add post to user dashboard
- Sync roles across several plugins
- Can I remove WooCommerce specific product categories from shop managers?