It IS possible, but I have never done it. You would need to use the is_filtered() function to see if the filter has yet been used (or has been reset) and then use sf_edit_query_args filter to change the incoming filters applied to the page. All this in your child theme functions.php file.
You might find ideas in this github repository from the developer of Search & Filter:
I’m using S&F on a custom post, but i’m unable to change the amount of posts it show on a page. It seems to be limited to the reading settings of wordpress.
I’m running S&F on a multi-site setup if that helps.
I have tried using pre_get_posts, it works initially but then reverts back to the wp limit once any of the filters are applied, even if you reset.
I’ve also tried the filter ‘sf_edit_query_args’ but that doesn’t play ball either
Hi Trevor,
I used the code bellow in the functions.php file. Shoudn’t I ?
Thank you 🙂
function filter_function_name( $query_args, $sfid ) {
//if search form ID = 1272, the do something with this query
if($sfid==1272)
{
//modify $query_args here before returning it
print_r($query_args);
echo “Yeahhhhhhhhhhhh”;
}
I have not yet had chance to implement this feature – as mentioned it only works with archives at the moment – I have just realised though if you are a dev and can do some coding this may already be possible using a filter:
And if so, modify the S&F query to only look inside that category
$query_args['category_name'] = "dogs"
So putting it all together:
function update_search_category( $query_args, $sfid ) {
//if search form ID = 225, the do something with this query
if($sfid==225)
{
//here we check to see value is associated with the page
if(has_category( 'dogs', get_the_ID()))
{
$query_args['category_name'] = "dogs"
}
else if(has_category( 'cats', get_the_ID()))
{
$query_args['category_name'] = "cats"
}
else if(has_category( 'snakes', get_the_ID()))
{
$query_args['category_name'] = "snakes"
}
}
return $query_args;
}
add_filter( 'sf_edit_query_args', 'update_search_category', 10, 2 );
One big caveat I just realised, you may have to disable ajax – this is because an ajax request gets sent off somewhere else, and I think has_category will never give the correct result in an ajax request.
There shouldn’t be a custom query inside the filter itself, the filter is used to modify the arguments before they get passed to a query – the code should look like:
function results_map_filter( $query_args, $sfid ) {
//if search form ID = 1530, the do something with this query
if($sfid==1530)
{
//modify $query_args here before returning it
$query_args['posts_per_page'] = -1;
}
return $query_args;
}
add_filter( 'sf_edit_query_args', 'results_map_filter', 10, 20 );
Thanks
Author
Search Results
Viewing 10 results - 181 through 190 (of 205 total)
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
We also use cookies to store items in your cart as well as allowing your to login on the site.
You can adjust all of your cookie settings by navigating the tabs on the left hand side.
By continuing to use this site, you also agree to our Privacy Policy.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
*Other cookies used for logging in and cart functions will only be used when you use those features and cannot be disabled.
If you disable these cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!