3

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' => '=',
  ),
);
1
  • 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. Apr 25, 2013 at 2:50

1 Answer 1

7
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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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