filter by “price higher than”

Forums › Forums › Search & Filter Pro › filter by “price higher than”

Viewing 4 posts – 1 through 4 (of 4 total)
  • Anonymous
    #264344

    Hi,

    I need to filter the query, I need to get a filter that returns posts with meta “price” higher than value that user has filtered. I have tried this code, but is not working. Can you help me please?

    function filter_function_name( $query_args, $sfid ) {

    if($sfid==858){

    if(isset($_GET[‘_sfm_m2_from’]) && !isset($_GET[‘_sfm_price_from’])){

    $query_args[‘meta_query’] = array(
    array(
    ‘key’ => ‘m2_from’,
    ‘value’ => $_GET[‘_sfm_m2_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    );

    }

    if(isset($_GET[‘_sfm_price_from’]) && !isset($_GET[‘_sfm_m2_from’])){

    $query_args[‘meta_query’] = array(
    array(
    ‘key’ => ‘price_from’,
    ‘value’ => $_GET[‘_sfm_price_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    );

    }

    if(isset($_GET[‘_sfm_m2_from’]) && isset($_GET[‘_sfm_price_from’])){

    $query_args[‘meta_query’] = array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘m2_from’,
    ‘value’ => $_GET[‘_sfm_m2_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    array(
    ‘key’ => ‘price_from’,
    ‘value’ => $_GET[‘_sfm_price_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    );

    }

    }

    return $query_args;
    }
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    Regards

    Trevor
    #264380

    This is something we plan to address in V3 (due in a few months), but for now what you must do instead is to se the field as a range (From To) and set the TO value manually to a high number (well above any likely value). Then make sure there is no ‘Values Seperator’ set in the form field settings, and use CSS to hide the TO field in the front end.

    Anonymous
    #264412

    ok Trevor, thank your for your help!

    Trevor
    #264424

    Let me know how you get on and if I can close this thread?

Viewing 4 posts – 1 through 4 (of 4 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.