December 09 2013

WordPress easy way to display the number of search results

Tagged Under :

In prepping the new site design for my client, I need to show the total number of search results on my search page.

From the wordpress Forum I found 1 of the solution. Like the below example code.
$mySearch =& new WP_Query("s=$s & showposts=-1");
$num = $mySearch->post_count;
echo $num. "results";
But unfortunately, sometimes it still gave me the wrong count.

After that, I try print_r the variable wp-query and found this field: found_posts. the total number of results was correct. So my code now looks like this:
echo $wp_query->found_posts." results";

Make a Comment