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.
Related Posts
Relevanssi Live Ajax Search
...accessibility. A basic search form looks something like this: <form role="search" method="get" class="search-form" action="/"> <label> <span class="screen-reader-text">Search for:</span> <input type="search" class="search-field" placeholder="Search …" name="s"> </label> <input type="submit" class="search-submit" value="Search"> </form> With Live Ajax Search, the form should look like this: <form role="search" method="get" class="search-form" action="/"> <label> <span class="screen-reader-text">Search for:</span> <input......type="search" class="search-field" placeholder="Search …" name="s" data-rlvlive="true" data-rlvparentel="#rlvlive" data-rlvconfig="default"> </label> <input type="submit" class="search-submit" value="Search"> <div id="rlvlive"></div> </form> Search results templates The Live Ajax Search plugin uses templates to display the search results. Using templates means it is easy to override the default search results from your theme if you want to......} ); Changes from SearchWP Live Ajax Search Relevanssi Live Ajax Search is a fork of SearchWP Live Ajax Search. I forked it from version 1.6.1 because it looked like SearchWP Live Ajax Search wasn’t getting updates anymore. I also wanted to improve the Relevanssi compatibility. Relevanssi Live Ajax Search...
Installing Relevanssi and adjusting the settings
...words to the search query and in OR search that works as expected, widening the search. In AND search, it will restrict the search, so it won’t work. Enabling this option will make Relevanssi index the synonyms as part of the post content, making them compatible with AND searches. Index......operator OR search will return all posts where at least one of the search terms appears. AND search will only return posts that have all search terms in them. OR search will prefer posts that have all search terms in them, so in most cases it is the better option.......all on all search forms on the site. If a search form includes the searchblogs parameter, it will override this setting. You still need to modify the search results template to get working permalinks, this (and the next) setting is just a shortcut for setting the searchblogs parameter. Search some...
Related Posts
...Relevanssi uses a simple CSS grid to lay out the related posts. This setting determines the minimum width of each element. Experiment with different values to see what works. If you want to style the related posts, Relevanssi wraps everything inside div#relevanssi_related, the header is in div.relevanssi_related_grid_header, and the grid......itself is in div#relevanssi_related_grid. Each post is a div.relevanssi_related_post. If you want to make more extensive modifications, you can create your template. Relevanssi will look for the relevanssi-related.php template inside the current theme templates directory, and if it finds one, it will use that instead of the default template. When......<li class="relevanssi_related_post"> <a href="<?php echo get_permalink( $related_post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"> <?php echo get_the_title( $related_post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </a> </li> <?php } ); ?> </ul> </div> <?php endif; Single post settings There are also Related posts controls on post edit pages. You can disable the auto-append for...
Related searches feature
John Blackbourn wrote a cool related searches feature for Relevanssi Premium. It's included from version 1.7.4. In order to use the related searches, you must have search logging enabled and a good...
Multisite searches
...other hand, you can adjust the settings for each blog. Enabling the multisite search There are several ways to enable multisite searching. If you want all searches to be multisite searches, you can enable multisite searching from the Relevanssi searching settings. If you want only some searches to be multisite......searches, you need to adjust search forms to include a specific parameter that will enable the multisite searching. See “Changes to the search form” below. Changes to search results templates The search results templates require some changes, otherwise, the permalinks will be wrong. Inside the while (have_posts()) loop, add as......in the same WordPress network, use the searchblogs argument. You can add a hidden input field in the search form, for example. List the desired blog ids as the value. For example, searchblogs=1,2,3 would search blogs 1, 2, and 3. Here’s an example search form: <form action="https://www.relevanssi.com/" method="get"> <input id="s" name="s"...
Scroll result page to the search term
Relevanssi can highlight search terms on the posts. But how about scrolling the page to show the location where the search results are? That is also possible. It requires a bit of JavaScript on the...
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.
$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.
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?
Well, it can simply be that Relevanssi is more picky, particularly if you’re using the AND operator.