0

Assumptions:

  • Site is not public. Posts can only be viewed by logged-in users.
  • This is only the front end, I don't need limiting in the back end.
  • You are awesome and I am SO thankful for any help!

Let's say I have two custom WordPress roles:

  1. elephant
  2. cheetah

In the front end, I would like the "Show All Posts" page, which is the index of all posts, to only display posts added by users with the same role.

For example, if a user with the elephant role creates a post, then only users with the elephant role can see those and only those posts. Users with the cheetah role can only view posts created by others users with cheetah role.

Is there a modification I can perform within the codebase to accomplish this? Better yet, is there a plugin that can do this? I don't mind getting my hands dirty if no plugin comes to mind.

I'm sincerely thankful for any help.

  • on the creation of the CPT, set map_meta_cap to true : codex.wordpress.org/Function_Reference/register_post_type - then you can set to each role, the corresponding capabilities – mmm Sep 14 '17 at 6:31
  • @mmm - Thanks man! Any chance you could show me example code? Also, what file do you modify and place this code - index.php? – user3247114 Sep 14 '17 at 14:09
0

To do this, you need to add a category field on the user page. There you can assign the specific category to a certain user.

After that you need to make sure that when the user is logged in, Wordpress is looking at the current_user and assign that user to the post loop. This way the user will only see there assigned category.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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