I’m building a WordPress site that heavily uses Advanced Custom Fields, and need assistance on displaying check box arrays. I want to have a check box field that will do things based on which boxes are checked.
For example, I know that this code will display the boxes that are checked:
<?php
$values = get_field('services_offered');
if($values)
{
echo '<ul>';
foreach($values as $value)
{
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
?>
But I want to do things based on the checked boxes. For example, I'd like to display an image of a ball cap if the "Ball Cap" check box is checked. Make sense?
Thanks anyone!
Fahad Murtaza answers:
I think the array's name is product. Is it?
Fahad Murtaza comments:
If so, then the code will be as follows
<?php if(in_array(‘brand-one’, get_field(‘products’) )): ?>
<h2>Brand One</h2>
<?php endif; ?>
<?php if(in_array(‘brand-two’, get_field(‘products’) )): ?>
<h2>Brand Two</h2>
<?php endif; ?>
<?php if(in_array(‘brand-three’, get_field(‘products’) )): ?>
<h2>Brand Three</h2>
<?php endif; ?>
Fahad Murtaza comments:
Please share your ACF screenshot or export SCF settings to share so we can get your question 100%.
Kyler Boudreau comments:
Ignore 'products' as that was just a bogus example name I was using.
I've attached a screen shot of the ACF field. See that list of certifications? If they check one of those, I want the cert logo to appear on the page.
This would be easy if it were just one certification, because I wouldn't need this check box array, and could do a normal if (get_field()): statement.
Let me know if you need more info. Thanks!