Home › Forums › General Issues › Checkbox and PHP if…
HI,
First, a big congratulation for this huge and wonderful plugin for WP ! 🙂
Thanks to authors!
Well, after some several time elapsed on one of my research…
I need some help, I hope you’ll help me on this issue
I created a simple form with a checkbox control
with these values:
"en:english"
"fr:french"
and in my PHP Code, I would like to test, but it seems doesn’t work 🙁
This my code :
<?php if ((get_field('language') == 'en')) { echo "ENGLISH Flag icon"} else {} ?>
<?php if ((get_field('language') == 'fr')) { echo "FRENCH Flag icon"} else {} ?>
Result: Array text or nothing appears 🙁
The goal is to display or not a flag icon, if I check the option in ACF…
Thanks alot by advance,
Regards,
Nico.

Try this:
$lang = get_field('language');
if ( 'en' === $lang ) {
echo "ENGLISH Flag icon";
}
elseif ( 'fr' === $lang ) {
echo "FRENCH Flag icon";
}

Hi @mikosworld
You can use this code to test the value. That way you know what you are working with:
<?php
$lang = get_field('language');
echo '<pre>';
var_dump( $lang );
echo '</pre>';
die;
?>
ok Elliot, thanks but…
it gets this :
array(2) {
[0]=>
string(2) "en"
[1]=>
string(2) "fr"
}
How tests “en” checkbox is checked and test “fr” is checked ?

The topic ‘Checkbox and PHP if…’ is closed to new replies.
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.