If I do this from the documentation the ajax search drops to 5 but the full search page results also drop to 5.
Is there a way to get this to only apply to the ajax dropdown?
add_filter( 'pre_option_relevanssi_throttle_limit', function( $limit ) { return 5; } );
Never set the throttle to a value less than 100-200, that just gets you random results. The setting you’re looking for is posts_per_page
, and for Live Search specifically you can use the hook relevanssi_live_search_posts_per_page
.
add_filter( 'relevanssi_live_search_posts_per_page', function() { return 5; } );
Edit: But ah, you’re not using Relevanssi Live Ajax Search, but some theme-specific live search… For that, you can check the theme support to see if there’s a better method, but you can use the posts_per_page
to control this. I’m sure there’s a way to restrict only to the live search (maybe check the query variables for something indicative), but I don’t know what that is as I don’t know the Enfold theme.
-
This reply was modified 1 year, 1 month ago by Mikko Saari.
Thanks Mikko,
Can you confirm I have this in the right format? See my functions.php code below:
posts_per_page
and relevanssi_live_search_posts_per_page
is being ignored. Only pre_option_relevanssi_throttle_limit
is impacting the Ajax search and search page.
add_filter( 'posts_per_page', function() { return 5; } );
add_filter( 'relevanssi_live_search_posts_per_page', function() { return 5; } );
add_filter( 'pre_option_relevanssi_throttle_limit', function( $limit ) { return 200; } );
I have raised a ticket with Enfold support and will also share a link to this post if you can get back to me about the forat of the above.
posts_per_page
is a query variable, not a filter hook. It works like this:
add_filter( 'relevanssi_modify_wp_query', function( $query ) {
$query->set( 'posts_per_page', 5 );
return $query;
} );
The Relevanssi Live Ajax Search filter hook doesn’t work, because you’re using Enfold live search, not Relevanssi Live Search.
Thanks Mikko, I have raised a ticket with Enfold to see if they can update their settings. If not I’ll consider trying the relevanssi live search (I assume you mean the extra plugin).
I have commented out your code correction for now. The only way to adjust the ajax by default with enfold is to use pre_option_relevanssi_throttle_limit
as far as I can tell.
Open ticket on Enfold is here:
https://kriesi.at/support/topic/enfold-relevanssi-ajax-dropdown-limit/
I’ll see if they have any suggestions. For now I will limit the result numbers to between 50-200 so at least the Ajax search has some limits.
Hi Mikko,
Gunter at Enfold has provided the following code which works as expected:
if( wp_doing_ajax() )
{
add_filter( 'pre_option_relevanssi_throttle_limit', function( $limit ) { return 5; } );
}
I may adjust this to 25. I see what you mean about the accuracy of the search results.
That’s still not good. The throttle option is not designed for this purpose. It’s designed to be set at 500 posts to allow decent performance on big sites. It is not for controlling the number of results. It will make the results much worse.
Please ask the Enfold support if there’s a way to adjust the posts_per_page
parameter for the search. This parameter is made for this purpose, and will ensure the maximum quality of results.
Hi Mikko,
Gunter has provided another solution for this. It seems to work but is giving me different results to the search page. But the more specific the search the better the outcome is.
enfold\config-relevanssi\class-avia-relevanssi.php
Around line 170 you find:
$tempquery->query_vars = $search_parameters;
relevanssi_do_query( $tempquery );
Try the following:
$tempquery->query_vars = $search_parameters;
$tempquery->set( 'posts_per_page', 5 );
relevanssi_do_query( $tempquery );
Enfold are adding a filter to version 5.6.6 to address the problem. I am satisfied that it works as intended.
Thank you for your help.
Yes, that’s the correct solution. It’s good that they’re adding a filter there.
Yeah the guys at Enfold offer some of the best theme support I’ve ever encountered.
They have frequently added my suggestions to the core theme over the past 5 years.
There is also a small CSS fix as well that puts the ajax results into a dropdown:
.ajax_search_response {
max-height: 300px;
overflow-y: scroll;
}