Forums › Forums › Search & Filter Pro › changing filter results
- This topic has 4 replies, 2 voices, and was last updated 9 years, 2 months ago by Ross.
-
Anonymous(Private) October 1, 2015 at 1:10 am #26283
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.Ross Moderator(Private) October 1, 2015 at 5:11 pm #26335Hmm 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 checksf_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
Anonymous(Private) October 1, 2015 at 8:23 pm #26357Yes, 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’).
Ross Moderator(Private) October 5, 2015 at 9:38 am #26497Hey 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
-
AuthorPosts