Title: get_posts multiple meta_keys?
Last modified: August 21, 2016

---

# get_posts multiple meta_keys?

 *  Resolved [treschlet](https://wordpress.org/support/users/treschlet/)
 * (@treschlet)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/get_posts-multiple-meta_keys/)
 * One more question for today!
 * I’d like to run a get_posts query, and I’d like to specify multiple conditions
   based on multiple custom fields.
 * Namely something like:
    ‘boolean_field’ = ‘1’ ‘date_start_field’ <= current_date‘
   date_end_field’ >= end date
 * Is there a way to do this? currently all I can get to work is
    $args[‘meta_key’]
   $args[‘meta_value’] = ‘1’
 * but that of course only works for one field. I was trying to do something like
   
   $args[‘boolean_field’] = 1; $args[‘date_start_field’][‘le’] = currend_date
 * etc, but without the ‘meta_key’ specified nothing ever returns (the get_posts
   documentation seems to imply that this should work, but it does not)
 * note: no I’m not actually using ‘boolean_field’ as a field name, this is just
   for example 🙂
 * [https://wordpress.org/plugins/custom-content-type-manager/](https://wordpress.org/plugins/custom-content-type-manager/)

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

 *  Plugin Contributor [fireproofsocks](https://wordpress.org/support/users/fireproofsocks/)
 * (@fireproofsocks)
 * [12 years ago](https://wordpress.org/support/topic/get_posts-multiple-meta_keys/#post-4871780)
 * The “between” operator is tricky so it’s not supported directly. See [https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_posts#Operators](https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_posts#Operators)
 * There are, however, workarounds. E.g. you can get all the posts posted in a given
   month (or day or hour etc) using “starts_with”:
 *     ```
       $args['post_date']['starts_with'] = '2014-04';
       ```
   
 * You can set the “date_column” argument and then use the “date_min” and “date_max”
   arguments to specify an arbitrary range:
 *     ```
       $args['date_column'] = 'my_custom_field';
       $args['date_min'] = '2013-03-13';
       $args['date_max'] = '2014-04-14';
       ```
   
 *  Thread Starter [treschlet](https://wordpress.org/support/users/treschlet/)
 * (@treschlet)
 * [12 years ago](https://wordpress.org/support/topic/get_posts-multiple-meta_keys/#post-4871785)
 * Actually, what I’m really having trouble with now that I’ve fiddled with it some
   more, is the custom field queries not really working as expected. Maybe you can
   help shed some light.
 * //only returns posts with boolean_field checked
    `$query['boolean_field'] = '
   1';`
 * //returns ALL POSTS regardless of what’s checked
    `$query['boolean_field'] = '
   0';` or `$query['boolean_field'] = '';`
 * I can’t seem to just do a simple exclusion of a post from the query based on 
   a checkbox. Is this working as intended?
 *  Thread Starter [treschlet](https://wordpress.org/support/users/treschlet/)
 * (@treschlet)
 * [12 years ago](https://wordpress.org/support/topic/get_posts-multiple-meta_keys/#post-4871786)
 * I should also mention that these options don’t seem to work as expected either:
 * //returns Posts where boolean_field = 1 (expected would be the opposite)
 *     ```
       $query['boolean_field']['!='] = 1
       $query['boolean_field']['ne'] = 1
       ```
   
 *  Plugin Contributor [fireproofsocks](https://wordpress.org/support/users/fireproofsocks/)
 * (@fireproofsocks)
 * [12 years ago](https://wordpress.org/support/topic/get_posts-multiple-meta_keys/#post-4871787)
 * Try debugging the query using the debug option — if there’s a bug in the query
   generation, then please file a bug. It could be that null/zero values are not
   being stored in the database at all, in which case the query would fail: you’ll
   have to look at the raw data to determine that though.

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

The topic ‘get_posts multiple meta_keys?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-type-manager_c9c790.
   svg)
 * [Custom Content Type Manager](https://wordpress.org/plugins/custom-content-type-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-content-type-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-type-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-type-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-type-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-type-manager/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [fireproofsocks](https://wordpress.org/support/users/fireproofsocks/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/get_posts-multiple-meta_keys/#post-4871787)
 * Status: resolved