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.

I'm attempting to filter posts by a custom field that either are equal to 'new' or have not been set yet. I'm able to get either of those meta_queries to work on their own but when I use them in an 'OR' query, the 'NOT EXISTS" portion is ignored and the query returns every post that has ANY value set. Here is the sample 'meta_query' that is causing the strange behavior:

array(
  'relation' => 'OR',
  array(
    'key' => 'status',
    'compare' => 'NOT EXISTS',
  ),
  array(
    'key' => 'status',
    'value' => 'new',
    'compare' => '=',
  ),
);
share|improve this question
    
There is a patch in the trac ticket linked in the comments below, you could try applying that to your current install. As next release is 3.6, you ought to be ok. –  Andrew Bartel Apr 25 '13 at 2:50

1 Answer 1

array(
  'relation' => 'OR',
  array(
    'key' => 'status',
    'value' => '', //<--- not required but necessary in this case
    'compare' => 'NOT EXISTS',
  ),
  array(
    'key' => 'status',
    'value' => 'new',
    'compare' => '=',
  ),
);

That should do it.

share|improve this answer
2  
This is a known issue: core.trac.wordpress.org/ticket/23268 –  chrisguitarguy Apr 25 '13 at 1:41

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.