Support » Themes and Templates » How to display the number of search results found
11 years, 1 month ago
At the top of the search page, I would like to display the number of matching results that were found for the particular search.
Is there a specific command that I can use for this?
Many thanks for your responses.
I’m not sure there’s a way to get at the full queried object for this (as to count # of post/search hits), but through the use of a custom loop you could collect all posts from the search query, count them up, then display that result:
$search_count = 0;
$search = new WP_Query("s=$s & showposts=-1");
if($search->have_posts()) : while($search->have_posts()) : $search->the_post();
10 years, 8 months ago
Wow! This is excellent. Works like a charm.
10 years, 6 months ago
A shorter version is just to skip the loop entirely.
$mySearch =& new WP_Query("s=$s & showposts=-1");
$NumResults = $mySearch->post_count;
10 years, 5 months ago
Very useful; thanks!
I use this plugin
Results count 0.1
By Matthew Taylor.
Adds info to search results for how many matches were found
but his site is not working for me today 🙁
10 years, 1 month ago
After using posts_nav_link(), one can display the number of search results by doing this:
<?php global $max_num_pages, $paged, $posts_per_page; $wp_query;
if ($max_num_pages > 1)
echo ‘Showing results ‘;
echo $posts_per_page * $paged – $posts_per_page + 1;
echo $posts_per_page * $paged – ($posts_per_page – $wp_query->post_count);
echo ‘ of ‘;
echo $max_num_pages * $posts_per_page – ($posts_per_page – $wp_query->post_count);