My goal is to return posts based on a specific price range using
meta_query. The price in the admin that the user enters is a custom field, created using WPAlchemy. In the example below, the query would return any posts with a price value between 1000 and 1500:
'meta_query' => array( array( 'key' => '_my_price', 'value' => array( 1000, 1500 ), 'type' => 'numerical', 'compare' => 'BETWEEN', )),
It works fine if a price value was entered as
1200 (and stored as 1200 in the DB), but how could I get this working for prices that are stored in the database that have dollar signs and commas such as
$1,200, which is then stored in the database. The meta_query doesn't think this is a number and therefore returns no results.
Or maybe there's a better method. Would it be better to ditch the JS formatter on the input fields in the admin and instead add the dollar sign and comma separation on the front end? This seems more logical, but then it raises another question of how to prevent a user entering a dollar sign or comma formatting in the admin.