Home Forums General Issues Checkbox and PHP if…


Checkbox and PHP if…

    • Nico

    • July 8, 2013 at 2:46 am


    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:


    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,



  • @mikosworld,

    Try this:

    $lang = get_field('language');
    if ( 'en' === $lang ) { 
    	echo "ENGLISH Flag icon"; 
    elseif ( 'fr' === $lang ) { 
    	echo "FRENCH Flag icon"; 
    • Nico

    • July 8, 2013 at 8:52 am

    Arf, no result 🙁

    • Elliot

    • July 8, 2013 at 9:52 am

    Hi @mikosworld

    You can use this code to test the value. That way you know what you are working with:

    $lang = get_field('language');
    echo '<pre>';
    	var_dump( $lang );
    echo '</pre>';
    • Nico

    • July 8, 2013 at 10:42 am

    ok Elliot, thanks but…
    it gets this :

    array(2) {
      string(2) "en"
      string(2) "fr"

    How tests “en” checkbox is checked and test “fr” is checked ?

    • Elliot

    • July 8, 2013 at 3:23 pm
    if( in_array('en', $lang) )
    • Nico

    • July 9, 2013 at 1:16 am

    Excellent, it works now! thank you Elliot! 😀

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

The topic ‘Checkbox and PHP if…’ is closed to new replies.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.