Title: Advanced WP_Query
Last modified: August 21, 2016

---

# Advanced WP_Query

 *  [colin1388](https://wordpress.org/support/users/colin1388/)
 * (@colin1388)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/advanced-wp_query/)
 * I’ve gone through the Codex and Google trying to make this query work, but it
   doesn’t want to budge no matter how many examples I follow.
 * I’m trying to do a query on a custom field that allows me to select all data 
   with post_type of “homes” that has a “square_footage” >= [number] AND <= [number]
 * Here is what my current query looks like
 *     ```
       $args = array(
       	  'post_type' => "homes",
       	  'post_status' => 'publish',
       	  'posts_per_page' => -1,
       	  'meta_query' => array(
       			'key' => 'square_feet',
       			'value' => array( $nums[0], $nums[1] ),
       			'compare' => 'BETWEEN'
       		);
       	);
       ```
   
 * When I do a print_r on the $args varialbe, I get the following:
 *     ```
       Array
       (
           [post_type] => homes
           [post_status] => publish
           [posts_per_page] => -1
           [meta_query] => Array
               (
                   [relation] => AND
                   [0] => Array
                       (
                           [key] => square_feet
                           [value] => Array
                               (
                                   [0] => 1000
                                   [1] => 1250
                               )
   
                           [compare] => BETWEEN
                       )
   
               )
   
       )
       ```
   
 * I would greatly appreciate any help 🙂 Thanks!

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/advanced-wp_query/#post-4246301)
 * Try adding the ‘type’ => ‘numeric’ parameter to your meta_query:
 *     ```
       'meta_query' => array(
       			'key' => 'square_feet',
       			'value' => array( $nums[0], $nums[1] ),
       			'type' => 'numeric',
       			'compare' => 'BETWEEN'
       		);
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Advanced WP_Query’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/advanced-wp_query/#post-4246301)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
