Support

Account

Home Forums General Issues Conditional logic not working with Select Field

Helping

Conditional logic not working with Select Field

  • How can I use the select field conditionally? The example in the select field page does not work.

    This code will display the Username and below it says “We offer: Beef”

     $users = get_users();
                foreach($users as $user_id){ ?>
    <h4 class="card-title"><?php echo get_user_meta($user_id->ID,'nickname',true); ?></h4>
                    <?php $farmtype = get_field('farm_type', 'user_' . $user_id->ID); ?>
                    <?php if( $farmtype ): 
                            echo 'We offer: ' . implode( ', ', $farmtype ); 
                        endif; ?>
    <?php
    }
    ?>

    When I add this conditional code to show an icon if the term “beef” is in the $farmtype array nothing appears.

    <?php if( $farmtype == "Beef" ) { ?>
                    <img src="<?php echo get_template_directory_uri(); ?>/images/beef_ico.jpg" class="farm-type beef-farm" width="32" height="32" />
                    <?php } ?>
  • Solved.

     if( $farmtype && in_array('Beef', $farmtype) ) { ?>
    
                    <img src="<?php echo get_template_directory_uri(); ?>/images/beef_ico.jpg" class="farm-type beef-farm" width="32" height="32" />
                    <?php }
                    ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.