[How to] Display search result count on search page

You can decorate your search result page in WordPress by displaying search count in page title. Most WordPress themes show search results on search.php. We have to add just a few lines of code in our page title.

You can decorate your search result page in WordPress by displaying search count in page title. Most WordPress themes show search results on search.php. We have to add just a few lines of code in our page title.

Code

<h2>
<?php
$rt_search = &new WP_Query(“s=$s&showposts=-1”);
$rt_search_key = esc_html($s, 1);
$count = $rt_search->post_count;
echo ‘Search Result for <span>”‘ . $rt_search_key . ‘”</span>  –   ‘.$count;
if($count > 1 ) echo ‘ Results’; else echo ‘ Result’ ;
wp_reset_query();
?>
</h2>
Just add this code in page title. The result will look something like the image below. 🙂

Do drop in your comments and views.

One Comment

Alessandro August 30, 2011

I used this count in my website, but it return the number of the post in the page (10), not the total count.