438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+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;
329 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
PaulWinslow says

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

438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+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