Query with a meta value inside a given range

In this situation you will want to use the meta_query parameter, an example:

$args = array(
    'post_type'   => 'page',
    'post_status' => 'publish',
    'meta_query'  => array(
        array(
            'key'     => $key,
            'value'   => array($min, $max),
            'compare' => 'BETWEEN',
        ),
    ),
);

$query = new WP_Query( $args );

The possible values for for the ‘compare’ key are:

  • “=”
  • “!=”
  • “>”
  • “>=”
  • “<“
  • “<=”
  • “LIKE”
  • “NOT LIKE”
  • “IN”
  • “NOT IN”
  • “BETWEEN”
  • “NOT BETWEEN”
  • “EXISTS” (only in WP >= 3.5)
  • “NOT EXISTS” (only in WP >= 3.5)
  • “REGEXP” (only in WP >= 3.7)
  • “NOT REGEXP” (only in WP >= 3.7)
  • “RLIKE” (only in WP >= 3.7)

Default value is “=”.

Useful reading: