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 am using the WPAlchemy MetaBox Class to create additional metaboxs on my site. One has a section with a group of radio boxes. I've coded it as follows:

    <?php $mb->the_field('docposs'); ?>
    <input type="radio" name="<?php $mb->the_name(); ?>" value="yes"<?php $mb->the_radio_state('yes')?' checked="checked"':''; ?>/>Yes
    <input type="radio" name="<?php $mb->the_name(); ?>" value="no"<?php $mb->the_radio_state('no')?' checked="checked"':''; ?>/>No
    <input type="radio" name="<?php $mb->the_name(); ?>" value="unknown"<?php $mb->the_radio_state('unknown')?' checked="checked"':''; ?> />Unknown

What I would like to be able to do in my template is echo a string based on which box returns checked, something like:

if (checkbox == yes) {
    echo "If you wish to make";
} elseif (checkbox == no) {
    echo "an apple pie from scratch,";
} else {
    echo "you must first invent the universe";

But I cant make it work :(

This (and many ridiculous variations on this) just returns 'yes' instead of the echo.

if ($provenance_mb->the_value('docposs') == yes) {
 echo 'hello world';

Any help would be appreciated.

share|improve this question
up vote 0 down vote accepted

not sure what you are doing wrong, your code looks ok at first glance ... make sure you represent yes and no as string values ...

if ( 'yes' == $provenance_mb->get_the_value( 'docposs' ) ) {
    echo "If you wish to make";
} else if ( 'no' == $provenance_mb->get_the_value( 'docposs' ) ) {
    echo "an apple pie from scratch,";
} else {
    echo "you must first invent the universe";
share|improve this answer
Frustratingly, your code returns "yesyesyou must first invent the universe" Almost as if the 'yes' == $provenance_mb->the_value( 'docposs' ) and the 'no' == $provenance_mb->the_value( 'docposs' ) are calling it. – Isendra Aug 15 '11 at 4:23
Ah! I got it. There was an seperate function for returning the value called 'get_the_value' (which I swore I tried). the_value would only print it out. Thank you for the push in the right direction! (it seems like after hours of hitting a wall, as soon as I give in and ask a question I figure it out, and it is easy) – Isendra Aug 15 '11 at 4:29

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.