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.
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- How to Get All Posts with any post status?
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- Some doubts about how the main query and the custom query works in this custom theme?
- Wp get all the sub pages of the parent using wp query
- How to query for most viewed posts and show top 5
- WP Query where title begins with a specific letter
- WP_Query vs get_posts
- Using OR conditions in meta_query for query_posts argument
- Query Posts in a Predefined Order
- Order posts by ID in the given order
- WP_Query by post ID doesn’t work if post is in custom post_status
- Query Multiple Post types each with own meta query
- Get posts by menu ID
- Get the number of posts from the current page results
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- How to know which one is the main query?
- Get posts by meta data OR title
- Perform query with meta_value date
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- get query’s query string
- Meta Query with date and time on the same Day before given time
- get_the_title($postID) OR get_the_title()?
- Display Posts by modifying the where clause only for my query
- How do I create my own nested meta_query using posts_where / posts_join?
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- Best practice for multiple queries on page
- How can I style future post?
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to find out what “Blog pages show at most” is set to [duplicate]
- Multiple search queries on one page
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Pass the same object to multiple widgets in a template with one query
- Retrieve or Query Pages by ID
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Get images only if parent status is publish
- How do you query wordpress posts using a math formula between multiple meta field values?
- How add a custom posttype name using ACF field to a query post array
- How to display future posts – modified query still yields 404
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Too many posts cause slow load when paginating
- Page navigation doesn’t show when query category
- Multiple instances of Featured Image Query
- Can’t get drafts with WP_Query using post_status parameter
- How can I pick a single post from the latest 3?
- 2 loops on page – one with orderby rand second orderby date
- How do you Query posts with nothing in common?
- Query post with meta_query where date is not in future
- Next/Prev posts on same page
- My entry results are not consistently alphabetized
- Orderby query does not work for custom fields even with meta query
- Merge two queries and remove duplicate
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- Custom WP_query and integrating into theme file
- Pull posts from all categories if quantity is not met?
- Query_post 5 post first / last of post_id
- Calling body_class and wp_nav_menu for a different post
- query_posts() doesn’t seem to be called in my page
- Modify query to exclude certain ids and certain parents and its corresponding children
- Some doubts about how the main query and the custom query works in this custom theme?
- Fetching $_POST from Page Template into functions.php
- How to order by datediff in WP loop?
- how to exclude store in clipper theme wordpress code php
- Ordering Posts by parent category, name ascending
- Display post list within category list sorted by name [duplicate]
- Optimising specific Query with ACF meta objects
- How to organize a WP_Query’s list of posts by category and display category title?
- When should you use WP_Query vs query_posts() vs get_posts()?
- query_posts with sorting on a custom datestamp
- query post based on comparison
- How to query post ids liked by the Author
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- custom query to get posts
- get contents and permalink from a specified page
- Multiple loop for “featured” items returns wrong posts
- Having trouble using this post category query on multiple pages?
- Query Posts to fetch Posts with Unique Tag
- Help in query for list links
- Exclude categories and subcategories in QueryLoop
- query_posts problem – need help
- WordPress pagination returns the same posts
- Incorrect posts displayed on category page
- WP Query – Show custom posts only if user contain some user meta
- Show number of posts AND number on current page (cannot make it work)
- Give attachments an archive page, and exclude unattached ones
- new WP_Query with order args – no more distinction between categories
- Adding a language rule and displaying posts with a custom taxonomy term on its archive page
- Modify WordPress Search
- post per page for differents post types in a same query
- When to use WP_query(), query_posts() and pre_get_posts