Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(
          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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.