I'm very confused regarding the have_posts(). It returns an empty result even though I have one post that match the query.
The below code is used in a widget which should display exactly one post, if it exists. I use wordpress 3.3...
$singleargs = array('p' => 2040, 'post_type' => 'event', 'post_status' => array('any'), 'posts_per_page' => 1);
$singlequery = new WP_Query( $singleargs );
//print_r($singlequery);
echo "I'm here 1!!<br>";
while ( $singlequery->have_posts() ) :
echo "I'm here 2!!<br>";
$singlequery->the_post();
// output post data...
endwhile;
The above code outputs only "I'm here 1!!", nothing else. But if I remove the while ( $singlequery->have_posts() ) : and endwhile; then I get "I'm here 1!!", "I'm here 2!!" and the correct output of the post that was found. So why do $singlequery->have_posts() not return true!!???
get_posts
instead?p => x
part.