0

I have a custom template page where posts are shown from authors 1,2 and 3.

<?php $the_query = new WP_Query( 'posts_per_page=-5&author=1,2,3' ); ?>

How can I use get current user in this so that the posts are only visible to an author with one of those ID's (1,2 or 3) and are logged in?

In other words: Author 4 will not see any posts. Authors 1,2,3 will see each others posts if they are currently logged in.

Thanks very much in advance-

  • Please share the codes you have been trying to get this thing work... – Maruti Mohanty Nov 20 '13 at 18:09
0

If I'm understanding this correctly something along these lines should work.

$authors = array( 1, 2, 3 ); // privileged users array
$signed_in_user = wp_get_current_user(); // get current user

// check if singed in user is in authors array
if ( in_array( $signed_in_user->ID, $authors ) ) {
    $query = array(
         'posts_per_page' = -1,
         'author__in' = $authors
     );
}
else {
     // alternate query for other users
}

$posts = new WP_Query( $query );

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.