WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can't seem to find out what I'm doing wrong.

$args = array( 
    'post_type' => 'wr_event', // my custom post type
    'posts_per_page' => -1, // show all posts 
    'meta_query' => array(
             'key' => 'event_announced', // a custom field either "on" or "off"
             'value' => 'on',
             'compare'  => 'NOT IN'
$loop = new WP_Query( $args );

So all I want to do is loop through all wr_events but if an event has the custom field event_announced (a checkbox) checked I'd like to exclude it.

Ideas? I tried setting "on" or "off" for the value and tried different solutions for compare

share|improve this question
up vote 0 down vote accepted

Your current query will select posts that have a value in the key event_announced which does not equal on. What I think you want is NOT EXISTS, and you can omit value, since you are querying for posts that don't have the key, hence, it will have no value. Note that NOT EXISTS is only available in WordPress 3.5+

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.