2

I am creating a frontend mosaic view where i need to show the most recent posts. So i need to show all published posts to every visitor, but keep the private ones for the logged in users.

I know how to add the private posts, but I don't find a way to remove them from the query.

(Removing them from the results would work but, then, the number of posts on the page will vary depending on how many recent posts are private: this is not what I want!)

(As a workaround, I can refrain from publishing the private posts and showing the private on top of the published for the members...)

Any idea?

1 Answer 1

1

I believe get_posts returns all published (no-private posts) but does display password protected posts. In fact, by default, the standard WP_Query loop does this as well. So by default, private posts shouldn't appear.

If you wanted to display private posts for those logged in, and not those who are logged out, you could use the permissions parameter perm=>'readable'

$wp_query = new WP_Query( array( 'perm'=>'readable' ) );

This returns any posts the current user has permission to read. If they are logged out, then they only have permission to read published, non-private posts. Only those logged in, with the ability to read private posts will see the private posts.

Note

Password protected posts will still appear, but will obviously require a password to read the posts.

1
  • This answer solved the issue! I did already try to use the "perm" parameter, but in combination with other parameters... and it failed. Using only "perm" => "readable" indeed works! Thanks
    – a.l.e
    Commented Jan 20, 2012 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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