Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Group leader - A designated user creates private posts.

Group member - I want a certain subset of my users to be able to see it across the website (on taxonomy/tag pages as well as the actual single post page itself)

I have already stored group leaders IDs and group member IDs in my db.

The important part is that it works throughout the entire site.

Making the posts public and then using some logic in the content.php or single.php file is not good enough because it will mess up the paging on different parts of the site. This needs to be done at the post query level.

I've given permissions for my group members to view private posts:

    function grant_private_priv() {
        $subRole = get_role( 'author' );
        $subRole->remove_cap( 'read_private_posts' );
    }
    add_action('init', 'grant_private_priv');

I've hooked into the pre_get_posts action hook and can see every post query before it goes in.. but can't exactly out how to modify it to get what I want.

Basically I want to add any private posts to the query where the post author is the group leader and the current logged in user is part of that group.

Is there a better way to do this? Someone must have done this before.. to rephrase the problem slightly: some kind of teacher-student relationship website where students could be enrolled in multiple courses but see an aggregated view of all their teachers posts along with any public posts.

share|improve this question

put on hold as off-topic by toscho 19 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.