Skip to main contentSkip to footer

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

Chamber Dashboard Business Directory
The Chamber Dashboard Business Directory plugin has a business directory search that’s not compatible with Relevanssi. To disable Relevanssi in…
CM Tooltip Glossary
A Relevanssi Premium customer bumped into a weird problem with CM Tooltip Glossary (and probably Elementor). Using Elementor, CM Tooltip…

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