Quantcast
Channel: Aquagraphite » syamilmj
Viewing all articles
Browse latest Browse all 13

Option Tree Multiple Checkbox

$
0
0

Using the multi-checkbox options in Option Tree.

OK, let’s start with the basics. Checkbox basically used to turn on/off stuff. If you have an option called “Test Option”, and given it id “test_option”, with the only option “on”, then you’d want to check if this option is checked or not.

The simplest way to do that is by using the following code:

if (get_option_tree( 'test_option', '', false ) == 'on')


Say, you a have multiple checkbox with the following options:

  • Andy
  • Suzy
  • Robin

And you want to display or echo different line of codes for each of these options. For example, we have an option with id “test_option” and we wanted to display “whatever, dude” when Andy is checked:

<?php if (get_option_tree( 'test_option', '', false, true, 0 ) == 'Andy') {
echo 'whatever, dude';
} ?>

That looks simple enough, isn’t it?

If you compare the code to the previous one, you noticed that we’ve added true and the number 0. This basically tells that our options is an array, and we’re only grabbing the first item in the array. Then it checks if this item is equal to whatever we want to check it with, or in our case “Andy”.

Now for a full blown example:

<?php if(get_option_tree('test_option', '', false, true, 0 ) == "Andy" ) {
echo "whatever, dude";
} ?>
<?php if(get_option_tree('test_option', '', false, true, 0 ) == "Suzy" ) {
echo "whatever, woman";
} ?>
<?php if(get_option_tree('test_option', '', false, true, 0 ) == "Robin" ) {
echo "whatever, batdude";
} ?>

I didn’t understand it the first time either, so you can ask me questions below, or suggest improvements.


Viewing all articles
Browse latest Browse all 13

Trending Articles