I have a custom search results page that works fine except when an empty input box is submitted.
When an empty input box is submitted, the header on the results page displays "XX results found" (the total number of pages/posts on the website) but no results are listed on the page.
So it seems like the code displaying the header count is finding every page on my site, while the actual code displaying the results isn't finding anything. I don't care which behaviour is used for these empty searches (display everything vs. display nothing), but I'd prefer that the behaviour is consistent between the count in the header and the actual results.
This is the code for the header (that returns "XX results found"):
<h2>Search results for <?php $allsearch = new WP_Query("s=$s&showposts=-1"); $key = esc_html($s, 1); $count = $allsearch->post_count; _e(''); _e('“'); _e('<span class="searchTerm">'); echo $key; _e('</span>'); _e('”'); _e(' - '); echo $count . ' '; _e('found'); wp_reset_query(); ?> </h2>
And this is the code for the actual results (that returns nothing):
<div id="searchContent"> <?php global $query_string; query_posts( $query_string . '&posts_per_page=20' ); while(have_posts()) : the_post(); ?> <p> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <span class="searchDate"><?php the_time('j F Y'); ?></span> </p> <?php endwhile; ?> </div> <!-- search content -->