I group users by custom user roles so each user groups can view and edit each others CPT . the problem i face now is when i give the user role capabilities related to edit and delete others posts, the be able to edit ALL other users posts and this is not what i want , i want them to only edit and delete posts made by other users in the SAME USER ROLE .

The question:

  • i can get the custom user role i made for the current user.
  • Now i have the user role , How to get all posts made by users with this user role.
  • How to add these capabilities to the current user edit_others_posts, delete_others_posts for these posts only
  • 1
    They just need the edit_others_posts capability. Commented Dec 21, 2017 at 14:21
  • It allow them to edit all posts created by user in any role .. i need to allow them to edit only posts created by users in their role
    – moe fahmy
    Commented Dec 21, 2017 at 14:27

1 Answer 1


By giving each role the edit_others_posts capability, plus allowing each role to edit only one CPT, you actually getting what you want. no need to check anything about other users capabilities this way.

Maybe what you're missing is having a different capability set for each post type. e.g: if you have CPT called books you can create a custom capabilities corresponding only with books, edit_others_books for instance. It's very easy to code, you can read more about it here:http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types

Hope it's helpful.

  • thanks for help ituk , but all users already use the same CPT, it's job listing btw and it has already its own capabilities , so if i gonna give them this cap edit_others_job_listingthey will be still able to edit jobs posted by users out their user role
    – moe fahmy
    Commented Dec 23, 2017 at 12:12
  • I'm not sure I understand. lets assume you have 3 CPT's: cpt1, cpt2, and cpt3. you also have 3 user roles except the default wp roles: role1, role2 and role 3. role1 can only creat, edit or delete posts from cpt1, role2 only from cpt2, etc. this apply also for the edit_others_cpt. why would a user from role2 for instance be able to edit posts that were written by a role1 user, if the role1 user can only write cpt1 posts?
    – Ituk
    Commented Dec 23, 2017 at 16:34
  • No , i have one CPT , and unknown number of user roles because i generate them dynamically based in user meta key , for the purpose of group users .. the point is i want each group of user under the same user role to edit each others job listings
    – moe fahmy
    Commented Dec 23, 2017 at 16:41
  • ahh I get your problem now... let me think.
    – Ituk
    Commented Dec 25, 2017 at 7:42

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.