I realize that maybe this could be an already submitted question and I searched for it, but couldn't find it.

I've got the following simple meta query:

if (!is_admin() && is_post_type_archive('custom_post') && $query->is_main_query()) {
    $meta_query = array(
            'key' => 'is_hidden',
            'value' => 'on',
            'compare' => '!='
    $query->set('meta_query', $meta_query);
    $query->set('posts_per_page', -1);

What I expect is to get all the "custom_post" posts in the relative Archive page that DOESN'T have the "is_hidden" checkbox active (so an ''/empty value instead of 'on' -> this is the value I get from CMB2 custom field checkbox). But it doesn't work, as the result is no posts at all.

While if I set the 'compare' to "equal" ('=') it works – meaning: I get only all the posts with the "is_hidden" checkbox set to 'on'.

Maybe I'm missing something...

  • Do the posts without is_hidden set to on have another value? Or just no value at all? Apr 27, 2020 at 8:52
  • Hello jacob, ...just "no value". I've also tried to set the posts to "on" and save and then "off" again, you never know... but nope Apr 27, 2020 at 9:05

1 Answer 1


I've found the solution (I suppose): looks like that the right operator in this case is "NOT EXISTS". I've noticed that in the db postmeta table I've got only the records of the "is_hidden" key with value "on"...

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.