Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro changing filter results

Viewing 5 posts - 1 through 5 (of 5 total)
  • Jaroslav Huss
    #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.

    Jaroslav Huss
    #26291

    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.. :-/

    Ross Moderator
    #26335

    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

    Jaroslav Huss
    #26357

    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’).

    Ross Moderator
    #26497

    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

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.