• Resolved theatereleven

    (@theatereleven)


    I have an Advanced Custom Fields checkbox. When an option is checked, I want to show an image on the theme page. For example, if someone checks “hat” I want to show an icon of a ball cap.

    I know how to just print out the array:

    <?php
    
    		$values = get_field('services_offered');
    		if($values)
    		{
    			echo '<ul>';
    
    			foreach($values as $value)
    			{
    				echo '<li>' . $value . '</li>';
    			}
    
    			echo '</ul>';
    		}
    
    		?>

    But I need it to do the “if this box is checked” then “do this” type stuff for the check boxes.

    I also know how to do a normal PHP if statement for a single ACF field. But this checkbox array is killing me.

    Thanks for any help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter theatereleven

    (@theatereleven)

    Paid to get the answer from somewhere else. Here it is for anyone wanting to do this: basically, if your ACF check box field is called “services_offered” and one of the services was “ac” then it would look like this:

    <?php
    
    $values = get_field('services_offered');
    
    if(in_array("ac", $values )){
    ?>
    <div class="dealer-services-icon"><img src="<?php echo get_bloginfo('url'); ?>/media/icon-ac.png" alt="<?php the_field('focus_city'); ?> Air Conditioning Service" class="tooltips" title="Air Conditioning"></div>
    <?
    }
    
    ?>

    That works like a charm.

    Patrick

    (@pskinner1972gmailcom)

    Do you know if I can I also use this for select box?

    Thank you, @theatereleven !

    I needed this badly. Thanks for sharing.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to use "if then" with ACF checkbox array’ is closed to new replies.