I have a following search.php page (this is just the code required for problem presentation).
Why is my $total_results returning a number of posts found, but when I do a loop though it always print No posts found ?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_args = explode("&", $query_string);
$search_query = array('posts_per_page' => 10, 'paged' => $paged);
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
}
$search = new WP_Query($search_query);
$total_results = $search->found_posts; // this returns 50
?>
<?php if ($search->have_posts()) : ?>
<?php while ($search->have_posts()) : $search->the_post(); ?>
loop through posts
<?php else : ?>
No posts found.
<?php endif; ?>
Any suggestion much appreciated.

var_dump($search->posts);& see if that's as expected – Mridul Aggarwal Jan 28 at 10:49var_dump($search->posts);comes back asarray(0) { }– User789 Jan 28 at 11:16array(0) { }means no data is coming from the database. Check yourpagedparameter. 50 posts with 10 per page means thepagedparameter can be 5 at max – Mridul Aggarwal Jan 28 at 12:01var_dump( $search_query );– Michael Jan 28 at 15:08