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

I have three separate WP_Queries on a page. Each of them return custom post type items that have a certain checkbox checked and then display one of those randomly. The checkbox has been added using Custom Metaboxes and Fields for WordPress.

$front1_args = array(
    'post_type' => 'work-item',
    'meta_key' => '_cmb_work_front_large',
    'meta_value_num' => 1,
    'orderby' => 'rand',
    'posts_per_page' => '1'
$front1_query = new WP_Query($front1_args);
while ($front1_query->have_posts()) : $front1_query->the_post();    
  post content comes here

However unpicking the checkbox on a certain post sometimes has no effect. The query still returns all items that at some point have had the checkbox checked regardless if they have it now. Setting cache_results, update_post_meta_cache and update_post_term_cache to false has no effect.

Any ideas what might cause this? Is this a cache issue at all, or is CMB maybe at fault?

share|improve this question
up vote 1 down vote accepted

Found a fix. Apparently CMB doesn't use integers while saving values to database from custom checkboxes, but rather adds an on string when a checkbox is checked.

Also when a previously checked checkbox is unchecked, the corresponding row isn't removed from wp_postmeta table, but remains there with an empty value.

So this will return all posts that at some point have had the checkbox active:

'meta_key' => '_cmb_work_front_large',
'meta_value_num' => 1

And this will show only the active ones:

'meta_key' => '_cmb_work_front_large',
'meta_value' => 'on'
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.