I have a meta_query that gets all the items with a price range between 2 variables. My problem is that 10 000 is not the same as 10000. How can I fix this?
I have been googling but I’n not sure what to google so I’m not really getting anywhere.
Help would be appreciated
Thanks
Hanè
Edit – Code Added
$kw_min = mysql_real_escape_string($_GET['kw_min']);
$kw_max = mysql_real_escape_string($_GET['kw_max']);
$pr_min = mysql_real_escape_string($_GET['pr_min']);
$pr_max = mysql_real_escape_string($_GET['pr_max']);
if ( !empty( $kw_min ) && !empty( $kw_max ) && !empty( $pr_min ) && !empty( $pr_max ) ) {
$args = array(
'post_type' => 'exc_agriq_equipment',
'exc_equipment_cat' => $term->slug,
'order' => 'DESC',
'posts_per_page' => 12,
'paged'=>$paged,
'meta_query' => array(
array(
'key' => 'exc_agriq_equipment_kw',
'value' => array( $kw_min, $kw_max ),
'type' => 'numeric',
'compare' => 'BETWEEN'
),
array(
'key' => 'exc_agriq_equipment_price',
'value' => array( $pr_min, $pr_max ),
'type' => 'numeric',
'compare' => 'BETWEEN'
),
),
);
}
3 Answers
The problem is that you’re comparing 10000
and 10 000
as strings, and as such they are not the same value.
So, you either need to sanitize the strings to ensure that both return an equivalent value, or you’ll need to force them to be integers, so that they’ll be evaluated as the same value.
Edit
Your best solution is probably to replace your text form field with a select, that includes pre-determined entry values (e.g. 10,000, 20,000, 30,000, etc.). That way, you will have reliable data to use in your meta_query
.