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 to use WP_query(), query_posts() and pre_get_posts
- Nested meta_query with multiple relation keys
- WP_Query vs get_posts
- Using OR conditions in meta_query for query_posts argument
- 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
- How to know which one is the main query?
- get query’s query string
- Meta Query with date and time on the same Day before given time
- How can I style future post?
- 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
- WordPress query for most recent posts from multiple categories
- Get images only if parent status is publish
- How add a custom posttype name using ACF field to a query post array
- Page navigation doesn’t show when query category
- 2 loops on page – one with orderby rand second orderby date
- Next/Prev posts on same page
- How to query a custom post type with a taxonomy filter but display post type archive page?
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Five posts from a category in footer
- Change query_posts to WP_Query in page but does not work
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- Serve specific “template” page at any URL that ends in its slug
- How to display multiple custom fields with the same meta_key in an ascending order?
- new WP_Query(), have_posts() return false in user_register hook
- Slow page loads due to WordPress Core Query
- how to make members list directory through wordpress post custom meta key.
- Add class to first post in custom loop using post_class filter
- Some doubts about how the main query and the custom query works in this custom theme?
- How to exclude post formats from wordpress recent posts in a tabs widget [closed]
- How to increase load time of an archive/search page (WP_Query)
- Query Page Content From Theme Options?
- Query all posts if multiple meta key don’t exist
- Is there a better way to pull in custom content without querying posts?
- How to get all post except particular category without breaking the paging
- How do I rewrite this loop as a new WP_Query style-loop?
- Include current post into loop
- Filter Custom Taxonomy Posts
- How to provide meta_key array to wp_query?
- Easy way to write complex queries in wordpress
- Filter post query to only show direct children of category
- Order post type by sum of two custom fields
- Why won’t draft listings appear for non-admins?
- get_posts output always same post
- Query_posts works when appending via AJAX call wp_query doesn’t?
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Posts Query | Query to only show sub categories
- How do I add a relation parameter to my filter query?
- Creating attachments archive in tags and categories
- Get next/prev image/attachment in time with date query
- Show single posts date, in a page of posts
- specific post is not excluded from the loop
- Why doesn’t my WP Meta Query return any results?
- Paginate pages with dynamic query
- filter posts by meta key with pagination
- Trouble Making WP_Query paged
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- WP_Query Class custom field parameters
- Add AJAX “Load more” on custom query block
- Optimising WP_Query with ACF Fields
- Elementor posts custom query based on tag [closed]
- Filter products on category AND tag
- Facing problem with tax_query results
- How do I stop the same post showing multiple times in a archive?
- Get posts that match defined arrays of tags
- WordPress post_status and meta_query
- trying to change from query_post to WP_Query
- How to query most recent post for each author?
- I need query_posts() to order results first by a meta value and then by post ID
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- How to search CPTs in draft using get_page_by_title()
- How to show post title in content editor in backend?
- Orderby query does not work for custom fields even with meta query
- Custom WP_query and integrating into theme file
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Fetching $_POST from Page Template into functions.php
- Ordering Posts by parent category, name ascending
- Optimising specific Query with ACF meta objects
- How to organize a WP_Query’s list of posts by category and display category title?
- query_posts with sorting on a custom datestamp
- query post based on comparison
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- Multiple loop for “featured” items returns wrong posts
- Having trouble using this post category query on multiple pages?
- query_posts problem – need help
- 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