Change filter value before getting the posts

Forums › Forums › Search & Filter Pro › Change filter value before getting the posts

Tagged: ,

Viewing 7 posts – 1 through 7 (of 7 total)
  • Anonymous
    #274897

    Hi! I would like to know if there is a hook or something that I could use to alter the value of a filter before getting the posts. What I want to do is a range that works as follows:
    I have a post type that has a price meta value. The price can be any number.
    I have a search filter for that meta value and whant it to be a range field, with the min value being 1 and the max value being 100.
    I want that, if anyone select 100 as the max value, the results would show that have 100 or more as their value.

    As far as I know, I can’t accomplish this using the form settings when creating the search form, so what I was looking for, is to have a way to do execute a code like:

    If ( field_value == max_field_value) {
    field_value = 99999999
    }

    Thanks in advanced!

    Trevor
    #274941

    There may well be a way, yes. Are you able to send me a live link/URL to your search page so I can take a look?

    Anonymous
    #275085
    This reply has been marked as private.
    Trevor
    #275183

    It may be that you can do this using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    If you need help with the coding, I would need to refer this to our plugin developer, Ross, for his input.

    Anonymous
    #275427

    Hi Trevor, thanks for the response. I tried using the hooks that you mention but it seems the search filter values are not passed in that query, this is what the var_dump of the query looks like

    
    array (size=10)
      'paged' => int 1
      'search_filter_id' => int 156
      'search_filter_override' => boolean false
      'posts_per_page' => int 5
      'post_status' => 
        array (size=1)
          0 => string 'publish' (length=7)
      'meta_query' => 
        array (size=3)
          0 => 
            array (size=4)
              'key' => string 'end_date' (length=8)
              'value' => string '20210205' (length=8)
              'type' => string 'DATE' (length=4)
              'compare' => string '>=' (length=2)
          1 => 
            array (size=4)
              'key' => string 'status' (length=6)
              'value' => string 'closed' (length=6)
              'type' => string 'CHAR' (length=4)
              'compare' => string '!=' (length=2)
          2 => 
            array (size=4)
              'key' => string 'status' (length=6)
              'value' => string 'cancelled' (length=9)
              'type' => string 'CHAR' (length=4)
              'compare' => string '!=' (length=2)
      'post_type' => string 'property' (length=8)
      'is_search' => boolean true
      'orderby' => 
        array (size=1)
          'date' => string 'DESC' (length=4)
      'lang' => string 'en' (length=2)
    

    so the values for the price and other filters are not being passed in that array.

    Ross Moderator
    #275742

    Hi Juan

    I’ve been doing a pass of these forums and realised I had never got back to you, apologies.

    Unfortunately I can’t see a way to do what you want.

    Essentially the issue is that the meta query for price is not in the query – and that’s because we peform that part in a custom query, and return the IDs.

    So right now, I can’t see a way for you to condtionally modify those filters.

    I’m going to tag this post with v3 – as in, something I would like to add to v3, once the intial release is out.

    Thanks

    Anonymous
    #275760

    Hi Ross, thanks for the response, it’s a shame is not currently possible. I’ll look forward to it.

Viewing 7 posts – 1 through 7 (of 7 total)

Search & Filter Support
Privacy Overview

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.