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.

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?

share|improve this question

1 Answer 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.

share|improve this answer
    
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 Jan 20 '12 at 11:56

Your Answer

 
discard

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.