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