WP_Query
has a bug (#29167) when you try to fetch posts with (almost?) any other status than publish
. This bug seems to be fixed in trunk. I haven’t tested it, so I cannot tell if it covers your use case. Try it, and give feedback there if it doesn’t.
There are two workarounds:
-
Use
get_post( $post_id )
. This runs its own query and isn’t affected by this bug. -
Use a custom DB query if you don’t know the post IDs:
$sql = "SELECT * FROM $wpdb->posts WHERE post_status = %s AND post_type = %s";
$prepared = $wpdb->prepare( $sql, $status, $post_type );
$posts = $wpdb->get_results( $sql );
Related Posts:
- How to Get All Posts but the Private ones?
- How can I style future post?
- Get images only if parent status is publish
- How to display future posts – modified query still yields 404
- Can’t get drafts with WP_Query using post_status parameter
- Wp_query Add specific pending posts
- Show scheduled posts in main loop but not in WP_Query?
- wp_query ignoring custom post_status
- Does the WP_Query ‘private’ argument for post status only apply to privately published content?
- Why won’t draft listings appear for non-admins?
- WP_Query will not display draft posts
- WordPress post_status and meta_query
- Give attachments an archive page, and exclude unattached ones
- WordPress get_posts function, 1300 lines long
- Exclude a category if post is only in that category using wp_Query
- Sorting posts by custom date fields (non standard date format)
- How to filter sql only for a specific post type
- Loop with break in the middle
- What should I use, get_posts or wp_query for less CPU load?
- How should I use posts_where to change meta_value from a string to integer?
- Reduce Database Queries in Code [duplicate]
- How to get post from all Blog Multisite to the Main Site?
- meta_query with array as value
- Sort in WP_Query(), not filter? Is it possible?
- Determine WP_Query parameters from URL
- Using WP Query to search within ALL keys in meta query
- Search product by brand name in wp_query
- wordpress query in header won’t reset and corrupts other loops
- How add a custom posttype name using ACF field to a query post array
- WP User Query multiple AND OR query problem
- Php Trying to get property ‘ID’ of non-object
- More than 1 Year Date Query
- Is it possible to dynamically get queried term AND taxonomy?
- posts_per_page not working
- Pull post meta with post_query?
- How to use WP_Query to display many posts?
- How do I force WP_query to fetch fresh, non-cached results?
- Complex WP_Query (two post types and multiple operators)
- Five posts from a category in footer
- Remove category from query (show all posts in archive.php) pre_get_posts()
- How to Union two different conditions in one WP_Query
- Display filtered results into custom page
- WooCommerce – get product sub categories
- Order by empty custom field
- WP_Delete_user link creation
- How to exclude post formats from wordpress recent posts in a tabs widget [closed]
- New WP_Query loop in admin causes problems
- How to pass orderby params to $wpdb->prepare()?
- Get author if post has multiple authors
- how update data through ajax and jquery
- What happens to the default query when I use WP_Query?
- WP_Query arguments relation shows AND instead of OR
- Combine results of multiple WP_Query to resemble single WP_Query
- Modifing archive query affects show post count function
- Using WP_Query() in Magento shows error
- For what queries is conditional tags informative?
- Utilising an existing page while using the “s” query parameter
- posts archive page – closing WP_Query loop correctly [closed]
- AJAX Breaking Offset Argument In WP Query
- Get meta_value of a specific meta_key from all posts belonging to a specific custom type
- Pagination in html table is not working
- Nested array issue in meta_query
- Why does WP_Query have methods that return public properties of the same name
- Query by key or author
- Don’t repeat posts from children in parent taxonomy query
- WP_query paged pagination with excluded category still counts it
- meta_query with array as value with multiple arrays
- Why doesn’t my WP Meta Query return any results?
- How to make the ‘request’ filter work?
- Filter for each loop when WP_Query has no posts to show
- How sort products by calculate value? ( custom post meta, price, option)
- wc_get_products() return empty object
- Ascending numerical sorting with non-numerical characters last
- WP_Query not returning custom post type
- How do I use $wp_query->current_post with get_template_part? I’m trying to add post classes (first/last/even/odd) to custom loops
- Why pagination is not working with tax_query param?
- Finding post ID dynamically on click
- paginate_links method doesn’t show second page of my custom wp_query
- ACF Post Object meta-query by title not ID
- Case insensitive ORDERBY in wpquery
- Sorting with meta_query and multiple, optional meta keys
- getting posts by tags
- WP_Query & Duplicate entries
- Query child posts with tax query on parents
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Include post_status check within $wpdb query
- Return on a quest all these meta_value
- Inline Ajax call after term is appended with a @ or # etc. displayed in div
- Complicated WP_Query
- Query custom post type by date field only working when two posts match the query
- Why isn’t my Meta_Query running?
- Custom query to show posts
- How to specify a certain amount of images queried, not all?
- Taxonomy related query not working
- How to show featured post first, then separate loop for other posts
- error with $query->have_posts()
- Multiple Orderby is not working right
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge