Skip to main contentSkip to footer

Showing the number of search results

If you want to show the number of search results found on the search results template, you can find the value in the variable $wp_query->found_posts. Just add

<?php echo '<p>Found ' . $wp_query->found_posts . ' hits.</p>'; ?>

in your search results template. In case that produces no results, try introducing the global $wp_query variable like this:

<?php global $wp_query; echo '<p>Found ' . $wp_query->found_posts . ' hits.</p>'; ?>

The usual method which involves a new WP_Query object does not work with Relevanssi.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

How to display relevancy score
Relevanssi stores the relevance score it uses to sort results in the $post variable. Just add something like <?php echo…
Divi

Make Divi include all post types Divi search form module restricts the search to only posts and pages. To get rid of that restriction, you can add this to your site: add_action( ‘pre_get_posts’, function() { unset( $_GET[‘et_pb_searchform_submit’] ); }, 1 ); Divi and multisite searching Divi search results templates don’t……work in multisite searching. Multisite searching requires changes to the templates, and it’s impossible to make those changes in the Divi Blog module. If you want to do multisite searching with Divi, you need to use a standard WordPress search results template for the results. Getting Divi to show Relevanssi……excerpts Divi doesn’t use the default excerpts but instead truncates the beginning of the post and shows the first 270 characters. That means Relevanssi-generated excerpts don’t show up at all. However, you can configure Divi to show Relevanssi excerpts. Just enable the “Use excerpts when defined” setting in Divi settings,…

Related Posts:

Comment Section:

4 Comments. Leave new

  • Hello Mikko,
    if Relevanssi is active, the search result yields less posts than the normal WP search. The difference is high sometimes, eg. without Relevanssi “59 posts found”, with Relevanssi “14 posts found”.

    Posts to be indexed are “all public post types”. There are no other exclusions and restrictions (if I see it correctly).

    Are there any other magic filters? What is the reason for such a difference?

    Reply
  • $query->found_posts is the number of documents with hits. I tried this on my blog, and the number shows the amount of results and didn’t change, even if I added the search term in the documents.

    Reply
  • Pace McCulloch
    November 3, 2011 8:13 pm

    This doesn’t seem to be the # of results, but the number of times that search term was found. Therefore if you search for a term and one page has the term 34 times, the output would be 34 even though there is one result in the list.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed