Home Forums General Issues If a checkbox value is checked Reply To: If a checkbox value is checked

  • Here was a simple solution that I came up with for a single checkbox. My use is to declare a title to be echoed as an <h2> or <h3> tag in the html. I post this for anyone else looking for an easy way to use a single checkbox.

    if($h3 = get_sub_field('h3_option')){
                                            echo "<h3>{$title}</h3>";
                                    } else {
                                            echo "<h2>{$title}</h2>";

    I tried the “basic logic” option in on this page:

    $selected = get_field('field_name');
    if( in_array('red', $selected) ) {
    	echo 'Red was selected!';

    But I found it unnecessary for my single selection.

    Do note the “get_field” and “get_sub_field” difference in the 2 examples.

    I am using sub_field because we are using the flex content. Big difference for those just getting to know this plugin.