Home / search / Display number of search results
  • How to Display number of search results

    no thumbnail sorry: Display number of search results

    Adding this PHP code to your wordpress theme will display the total number of results returned.

    ( click code to copy )

    wordpress snippet : PHP

    <h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' &mdash; '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>

    ( WordPress codex functions, hooks, in this snippet. )

    query, wp_specialchars, _e, wp, wp_reset_query,
  • Pingback: Tweets that mention Wordpress Display number of search results – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com()

  • Harvy

    Hi Kevin, thanks a lot for your snippets, they are so useful!

    I’m using a dropdown menu form to search for posts using specific categories. The problem with your snippet is that it shows all the results from all the categories. I want to show only the number of results for the selected category.

    I hope you can do that or else I’m really stuck because I’ve searched everywhere for an answer with no luck so far… Thanks a lot! :)

    PS: Maybe you could update your snippet and replace showposts by posts_per_page since showposts is now deprecated.