skip to Main Content

I have a repeater field that has a yes/no select. If not, then a class is added to the div, if yes, then nothing happens. Now, when selecting one element with the value "no", the class is added to all elements. How can I add it for one element?

$team_cards = get_field('team_cards');

$noimage = '';

foreach ($team_cards as $item) {
    if ($item["yes_no"] == "no") {
        $noimage = "no-image";
    }
}

 <div class="<?php echo $noimage ?>"></div>

2

Answers


  1. Try this code

    <?php 
    $team_cards = get_field('team_cards');
    
    $noimage = '';
    
    foreach ($team_cards as $item) {
        if ($item["yes_no"] == "no") {
    ?>
            <div class="no-image"></div>
        <?php 
    }else{ ?>
            <div class="”></div>
    <?php
        }
    
    
    }
    
    Login or Signup to reply.
  2. $team_cards = get_field('team_cards');
    
    foreach ($team_cards as $item) {
        if ($item["yes_no"] == "no") {
            $noimage = "no-image";
        }else{
            $noimage = "";
        }
    }
    
     <div class="<?php echo $noimage ?>"></div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search