I'm using Custom Meta Boxes and Fields by Justin Sternberg and its pretty great, however there's been a huge issue with using the multicheck checkbox options for me.

This is what the plugin's code returns:

'_cmb_seostats_multicheckbox' => 
    array (size=22)
      0 => string 'alexa_tr' (length=8)
      1 => string 'alexa_bl' (length=8)
      2 => string 'google_pr' (length=9)
      3 => string 'google_bl' (length=9)
      4 => string 'indexed_x' (length=9)

How do I test those checkbox options within an if statement?

  • This appears to be a basic PHP array syntax issue.
    – s_ha_dum
    Feb 5, 2014 at 15:17
  • You're a a basic PHP array syntax issue. Feb 13, 2014 at 22:18
  • Hmmm... can't quit tell if that is an attempt at an insult or not. You might read the site's behavior section of the site's FAQ, just in case.
    – s_ha_dum
    Feb 13, 2014 at 22:29

1 Answer 1


Use the in_array() function, like so:

if ( in_array( 'check2', $test_multicheckbox ) ) {
    echo 'Check Two is checked';
  • This is exactly what I've been trying. It only returns true for my first position 'alexa_tr' all others return false. Feb 5, 2014 at 19:40
  • This is how you would grab that data. But my issue was that get_post_meta had a true argument -> "If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array" Feb 6, 2014 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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