Looking for support? You can access the support system via your account.
- This topic has 4 replies, 2 voices, and was last updated 8 years, 6 months ago by .
You must be logged in to reply to this topic.
Looking for support? You can access the support system via your account.
Forums › Forums › Search & Filter Pro › changing filter results
Hi,
I need to change behaviour of a dropdown field. I have a field “English Level” where are values “Basic, Advanced, Intermediate, Fluent” and when is selected for example “Advanced” level I need to return all posts with Basic + Advanced levels and not only those with Advanced level. How can I do that? I tried to use “pre_get_posts” filter and alter the query but it doesn’t work. I guess it’s because of the cache in your plugin.
So I’ve found that there is a new filter sf_edit_query_args which is exactly for this purpose. But when I try to hook there the $query_args argument is empty.. :-/
Hmm what are you trying to do, find out what the current search is, and modify the query based on certain criteria?
What I think you might want to do is, check what the current user has searched for by using the info here:
http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/
and then run sf_edit_query_args
– if you want to check sf_edit_query_args
after it has some values from S&F then run it with a lower priority (eg 100):
add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 100, 2 );
Thanks
Yes, exactly that I want to do.
I tried to set lower priority and it was the same like before. But I wasn’t clear when I wrote that the $query_args was empty, there was this:
array (
'paged' => 1,
'posts_per_page' => 10,
'post_status' =>
array (
0 => 'publish',
),
'meta_query' =>
array (
),
'post_type' =>
array (
0 => 'product',
),
)
And as you can see there is empty meta_query array. It’s empty always, even if I’ve setup the filter from frontend. Actually I tried to set the meta_query but it change nothing in results. But it works correct if I change the post_status to another one (eg. ‘draft’).
Hey there
I think I know the issue – I just didn’t think this through when replying to you.
The thing is, for all taxonomy queries, and meta queries, S&F uses its built in cache to search.
When the searching inside the cache has finished, it returns a bunch of post IDs to the WP main query, which means when you are filtering the query args, you do not see any of the taxonomy info, or the meta info – you would likely see a list of posts ID under the var posts__in
however this is actually added after this filter so users can’t mess with the cache.
So what you would need to do is use the active query stuff above, to detect what taxonomy & meta data is being used, and then use that filter to make any necessary modifications.
Does that make sense?
Thanks
You must be logged in to reply to this topic.
© 2024 Search & Filter Support. All Rights Reserved.
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 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.
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!
More information about our Cookie Policy