Using Advanced Custom Fields Pro and have a checkbox array that displays fine as long as at least one checkbox is checked. If none of them are checked, it errors out on the page.
I want it to just not show if things are not checked, as opposed to showing the error message.
Here's the working code:
<?php
$values = get_field('oil_application');
if(in_array("dietary", $values )){
?>
<div class="oil-permission"><img src="<?php home_url(); ?>/media/oil-icon-ingested.png" alt="<?php the_title(); ?> can be ingested" class="tooltips" title="<?php the_title(); ?> can be ingested"></div>
<?php
}
if(in_array("topical", $values )){
?>
<div class="oil-permission"><img src="<?php home_url(); ?>/media/oil-icon-topical.png" alt="<?php the_title(); ?> can be used topically" class="tooltips" title="<?php the_title(); ?> can be used topically"></div>
<?php
}
if(in_array("aromatic", $values )){
?>
<div class="oil-permission"><img src="<?php home_url(); ?>/media/oil-icon-aromatic.png" alt="<?php the_title(); ?> can be inhaled" class="tooltips" title="<?php the_title(); ?> can be inhaled"></div>
<?php
}
?>
The error I'm receiving on the browser page is:
Warning: in_array() expects parameter 2 to be array, string given in /home/billyjoe/public_html/wp-content/themes/os/single-oils-blends.php on line 96
Arnav Joy answers:
try this
<?php
$values = get_field('oil_application');
if( is_array($values) ) {
if(in_array("dietary", $values )){
?>
<div class="oil-permission"><img src="<?php home_url(); ?>/media/oil-icon-ingested.png" alt="<?php the_title(); ?> can be ingested" class="tooltips" title="<?php the_title(); ?> can be ingested"></div>
<?php
}
if(in_array("topical", $values )){
?>
<div class="oil-permission"><img src="<?php home_url(); ?>/media/oil-icon-topical.png" alt="<?php the_title(); ?> can be used topically" class="tooltips" title="<?php the_title(); ?> can be used topically"></div>
<?php
}
if(in_array("aromatic", $values )){
?>
<div class="oil-permission"><img src="<?php home_url(); ?>/media/oil-icon-aromatic.png" alt="<?php the_title(); ?> can be inhaled" class="tooltips" title="<?php the_title(); ?> can be inhaled"></div>
<?php
}
}
?>
Arnav Joy comments:
is this worked ?
Kyler Boudreau comments:
Arnav,
Nice! That worked. Much appreciated.