0

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.

0

1 Answer 1

0

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";
}
2
  • 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
    Commented Aug 15, 2011 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
    Commented Aug 15, 2011 at 4:29

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.