Title: wp_query with multiple fields not working
Last modified: August 20, 2016

---

# wp_query with multiple fields not working

 *  Resolved [Topher](https://wordpress.org/support/users/topher1kenobe/)
 * (@topher1kenobe)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/wp_query-with-multiple-fields-not-working/)
 * I have a custom content type called sportpages. It has fields called ecpt_link
   and ecpt_season. Link is a checkbox and season is a select box.
 * I have one post with link set to “on” and a season of “Fall”.
 * Using wp_query this works to get that one:
 *     ```
       $args = array(
               'post_type' => 'sportpages'
               ,'post_status' => 'publish'
               ,'posts_per_page' => 1000
               ,'meta_key' => 'ecpt_link'
               ,'meta_value' => 'on'
           );
       ```
   
 * This also worked to get that one:
 *     ```
       $args = array(
               'post_type' => 'sportpages'
               ,'post_status' => 'publish'
               ,'posts_per_page' => 1000
               ,'meta_key' => 'ecpt_season'
               ,'meta_value' => 'Fall'
           );
       ```
   
 * This however gets ALL posts, ignoring everything in meta_query:
 *     ```
       $args = array(
               'post_type' => 'sportpages'
               ,'post_status' => 'publish'
               ,'posts_per_page' => 1000
               ,'meta_query' => array(
                   array(
                       'meta_key' => 'ecpt_link'
                       ,'meta_value' => 'on'
                       ,'compare' => '='
                   )
                   ,array(
                       'meta_key' => 'ecpt_season'
                       ,'meta_value' => 'Fall'
                       ,'compare' => '='
                   )
               )
           );
       ```
   
 * I’ve tried it without the comparison operators as well. What am I missing?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Topher](https://wordpress.org/support/users/topher1kenobe/)
 * (@topher1kenobe)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/wp_query-with-multiple-fields-not-working/#post-2612823)
 * I figured it out.
 * Old code:
 *     ```
       array(
                       'meta_key' => 'ecpt_link'
                       ,'meta_value' => 'on'
                       ,'compare' => '='
                   )
       ```
   
 * new code:
 *     ```
       array(
                       'key' => 'ecpt_link'
                       ,'value' => 'on'
                   )
       ```
   
 * No metas in the meta_query.

Viewing 1 replies (of 1 total)

The topic ‘wp_query with multiple fields not working’ is closed to new replies.

## Tags

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

 * 1 reply
 * 1 participant
 * Last reply from: [Topher](https://wordpress.org/support/users/topher1kenobe/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/wp_query-with-multiple-fields-not-working/#post-2612823)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
