Home Forums General Issues Checkbox and PHP if…


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:


    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"; 
  • Arf, no result 🙁

  • 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>';
  • 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 ?

    if( in_array('en', $lang) )
  • 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.