Home › Forums › Front-end Issues › Chechbox not working in foreach › Reply To: Chechbox not working in foreach
Hi @unmatched
It’s possible that the “type” field doesn’t have value, so get_field() will returns an empty string while in_array() needs an array for the second parameter, not an empty string.
I think you can check if it has a value or not first like this:
$selected = get_field('type');
if($selected){
if( in_array('web', $selected) ) {
echo 'web';
}
}
I hope this helps.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.