Try replacing:
$search_results = new WP_Query( array( 's' => $s, 'posts_per_page' => -1 ) );
$total = $search_results->post_count;
with
$total = $wp_query->found_posts;
instead of instantiating a new WP_Query. Think that’s basically wiping out relevanssi.
Also note $wp_query->found_posts
will give you the total results for the query while $wp_query->post_count
will only return how many posts objects were returned for the current view. That is, you may have 40 total results for the term red
but if you have it set to display 10 results per page, post_count
will be 10
while found_posts
will be 40
. For normal WP searches, the code you have would be fine due to the -1 but Relevanssi doesn’t work with posts_per_page.
Thread Starter
Josh
(@joshjones)
Thanks for that! It seems that the search functionality works now and it displays the correct number of search results in the heading… However, Relevanssi doesn’t seem to be highlighting the search terms in the result? Is this something that will need to be changed in the way the theme handles displaying them?
Thanks again!
Make sure the content templates are using the_excerpt()
to show the excerpts, that’s how the highlighting works.
Thread Starter
Josh
(@joshjones)
That fixed it right up! You guys rock!