How to count number of search results returned by WordPress

Suppose you want to create a custom search result for your theme. Apparently you will create a php script named search.php. One problem is that, you want to display total number of search results returned. Here is the solution for that.

Searching for: < ?php echo get_search_query(); ?>

< ?php $allsearch = &new WP_Query("s=" . get_search_query() . "&showposts=-1"); $count = $allsearch->post_count; ?> < ?=$count?> results found:

Happy coding!