Title: Listing Posts Between Two Values
Last modified: August 20, 2016

---

# Listing Posts Between Two Values

 *  [Darryl](https://wordpress.org/support/users/darrylschmidt/)
 * (@darrylschmidt)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/listing-posts-between-two-values/)
 * I currently have a post that loops through my custom post type ordering by a 
   custom field called “price”.
 *     ```
       <?php query_posts(array('post_type'=>'listings','orderby'=>'meta_value_num','meta_key'=>'price','order'=>'ASC','posts_per_page'=>5,'paged'=>$paged)); ?>
       ```
   
 * What I would like to do now is list posts where “price” is less than 200 between
   200 and 350, and over 350.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/listing-posts-between-two-values/#post-2715809)
 * Here is a pastebin with some sample code that should get you started:
 * [http://pastebin.com/KiyJjfF6](http://pastebin.com/KiyJjfF6)
 * It used two filters to modify the query by joining the postmeta table and adding
   the meta_value field to the results.
 * You will need to add the post_type parameter as I tested it against normal posts.
 * Note that I did not say it was the best possible code – you could do without 
   the $price_points array and just hard-code the values in the if() tests.
 *  [LucP](https://wordpress.org/support/users/towonder/)
 * (@towonder)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/listing-posts-between-two-values/#post-2715829)
 * Your best chance to do this as a query (as apposed to getting all the content
   and then filtering it) is to use the meta_query method in WP_Query:
 *     ```
       $args = array(
       	'post_type' => 'listings',
       	'orderby'=>'meta_value_num'
       	'meta_query' => array(
       		array(
       			'key' => 'price',
       			'value' => array(200, 350),
       			'type' => 'numeric',
       			'compare' => 'BETWEEN'
       		)
       	)
        );
   
       $query = new WP_Query( $args );
       ```
   
 * Read more about it here: [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Listing Posts Between Two Values’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [LucP](https://wordpress.org/support/users/towonder/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/listing-posts-between-two-values/#post-2715829)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
