Support

Account

Home Forums General Issues If statement with check box array

Solved

If statement with check box array

  • Hey, I’m building another site with ACF Pro 5, and need assistance on checkboxes. I want to have a checkbox field that will do things based on which boxes are checked.

    Is this the right way to do it? My field is named “products”:

    <?php if(in_array(‘products’, get_field(‘brand-one’) )): ?>
    <h2>Brand One</h2>
    <?php endif; ?>

    <?php if(in_array(‘products’, get_field(‘brand-two’) )): ?>
    <h2>Brand Two</h2>
    <?php endif; ?>

    <?php if(in_array(‘products’, get_field(‘brand-three’) )): ?>
    <h2>Brand Three</h2>
    <?php endif; ?>

    Thanks anyone!

  • Anyone on this? I know that this will return the values:

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

    But I want to show a certain image for each checkbox, so I need if and then type statements. Meaning, if this checkbox is checked, display this image.

  • Anyone have an idea on this? I really need to be able to use check boxes with and “if” type setup.

    Thanks for any help!

  • 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>
    				<?
    				}
    
    				?>
  • Thanks heaps for this

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘If statement with check box array’ is closed to new replies.