438 posts
  • 4 Years of Membership
  • Exclusive Author
  • United States
christopherjon
says

With multiple checkbox options, how do I check to see which options were selected?

I’m missing something and I can’t figure it out.

Thanks 8-)

751 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Collector Level 2
  • Exclusive Author
+1 more
CyberShot
says

one thing you can do is open up the database and look in the tables for the values. When you are using check boxes with option tree, you test the key that you set. so for example. I set up two checkboxes to show and hide a box on the homepage. my key that I set up was called social_share and the value of the checkbox is Show and Hide so I can test for it like this


$options = get_option('option_tree'); 
if( $options['social_share'] == 'Show') :
     Do something here;
endif;
381 posts Simple is the new black.
  • Weekly Top Seller
  • Elite Author
  • Author Level 7
  • 5 Years of Membership
+5 more
PaulWinslow
says

This is useful for something I was trying to work out yesterday. Cheers CyberShot!

438 posts
  • 4 Years of Membership
  • Exclusive Author
  • United States
christopherjon
says

one thing you can do is open up the database and look in the tables for the values. When you are using check boxes with option tree, you test the key that you set. so for example. I set up two checkboxes to show and hide a box on the homepage. my key that I set up was called social_share and the value of the checkbox is Show and Hide so I can test for it like this

$options = get_option('option_tree'); 
if( $options['social_share'] == 'Show') :
     Do something here;
endif;

Thanks,

That does work for a single selected box but not when multiple boxes are selected.

What I am attempting to do,

I have checkboxes for meta information (Author, Date, Category and Tags) and information is shown based on what checkboxes are selected.

Showing results from multiple boxes selected is where I am running into problems.

751 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Collector Level 2
  • Exclusive Author
+1 more
CyberShot
says

well, you could use more than one if statement to test for all the values and then echo them if they are present

751 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Collector Level 2
  • Exclusive Author
+1 more
CyberShot
says

I am wondering if you could use a switch statement for this?


<?php $options = get_option('option_tree');
$my_option = $options['author_options'];
switch ($my_option) {
    case "author":
        echo "author info";
        break;
    case "date":
        echo "date info";
        break;
    case "category":
        echo "category info";
        break;
}
?>

I don’t know much about the switch statement. You could try something like this

by
by
by
by
by
by