$applicationQuery = new WP_Query(array( 'post_type' => 'page', 'post_status' => 'any' ));
if($applicationQuery->have_posts()){
$header_text = "Got post (GOOD)";
}
else{
$header_text = "No post (BAD)";
}
This same query, if I use page
for post_type
there are results in the query, but if I change post_type
to post
or my own custom_post_type
there's no result. Why? How can I fix this and query my custom post type?
I fixed the problem by adding
'post_status' => 'published'
into the query array.Edit: The root cause was because the custom posts were programmatically created (not via admin dashboard), and the
post_status
of those posts were set topublished
.Wordpress doesn't know
published
, by default it only recognizepublish
. Theany
value in the query doesn't actually look for "any" post_status, but "any recognized" post_status.