WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to make a post visible to only:

  1. The post author, irrespective of its user role.

  2. All users from a specific user role.

Other then these, no one should be able to see the post.

How should I approach this.

Note that I have only three user roles in WP. Admin, and 2 other custom roles.

share|improve this question

Give your custom roles the capability to "read_member_posts" or whatever. Then you could apply a filter to the_content()

add_filter( 'the_content', 'my_wpse20347_filter' );

function my_wpse20347_filter( $content )
    global $post;
    if( author_can( $post->ID, 'edit_posts' ) || current_user_can( 'read_member_posts' ) )
       return $content;
    {  // Everyone else sees this in place of the content.
       return '<p>Only members may view this post</p>';
share|improve this answer

We already got a plugin in the WPSE Plugin Repository written by BAinternet, that does exactly that.

share|improve this answer
Yeah and has been evolving much since i posted there. – Bainternet Jun 18 '11 at 15:07
Thanks for the link. But I want to apply the condition globally so that I don't have to select the roles for each post. I am checking the code of the plugin to learn how to do that. But if you guys can post the snippet, it will save me some time :) Thanks for help! – AgentWP Jun 18 '11 at 17:21
And vice versa: It would save us a lot of time if you check it yourself :) – kaiser Jun 18 '11 at 18:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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