Forums › Forums › Search & Filter Pro › filter by “price higher than”
- This topic has 3 replies, 2 voices, and was last updated 4 years ago by Trevor.
-
Anonymous(Private) October 27, 2020 at 10:42 pm #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(Private) October 28, 2020 at 10:56 am #264380This 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.
-
AuthorPosts