Post visibility on the basis of roles

How to make a post visible to only:

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

    Read More
  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.

Related posts

Leave a Reply

2 comments

  1. 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;
        }
        else
        {  // Everyone else sees this in place of the content.
           return '<p>Only members may view this post</p>';
        }
    }