WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using WP_Query for visitor to filter the posts. The posts is about products. So in the filter, it has a field where user can select Maximum price and Minimum price. (Just like most of the shopping site).

Okay this is the filter form that I use to collect the user input:

 <lable>Min. Price ($)</lable> 
 <select name="minprice">
 <option value="0">0</option>
 <option value="100">100</option>
 <option value="200">200</option>
 <option value="300">300</option>

 <lable>Max. Price ($)</lable> 
 <select name="maxprice">
 <option value="100">100</option>
 <option value="200">200</option>
 <option value="300">300</option>
 <option value="400">400</option>

And this is the function that handle the inputs :

function filter_search() {
$max = $GET_['maxprice'];
$min = $GET_['minprice'];

$args = array(
'post_type' => 'product',
'meta_query' => array(
 'key' => 'price',
 'value' => array($min,$max),//this is the line where i cant figure out how.
 'compare' => 'BETWEEN'
 $searched_posts = new WP_Query( $args);
 return $searched_posts;

Am I correct to use the array for the value that I wish to compare?

share|improve this question
Have you tried this? What happened? Your code snippet doesn't contain a loop which may be your only problem. – mrwweb Jul 26 '12 at 20:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.