Support

Account

Home Forums Add-ons Repeater Field Accessing sub fields from multiple repeaters Reply To: Accessing sub fields from multiple repeaters

  • There isn’t a way to do this using have_rows loops. To do this you would need to get both of the repeater fields as arrays and loop through them, something like

    
    $regular = get_field('breakfast_mf_regular_price');
    $special = get_field('breakfast_mf_special_price');
    

    both of these will hold an array of rows. But since there’s no guarantee that the rows of the second repeater will align with the rows of the first repeater, there really isn’t going to be an easy way to check to see which value you should use.

    Basically you need to loop through one of them and then loop through the other. This is a really basic example of plucking one sub field out of one of two arrays.

    
    foreach ($regular as $r_row) {
      $price = $r_row['price'];
      foreach ($special as $s_row) {
        if ($r_row['name'] == $s_row['name']) {
          $price = $s_row['price'];
        }
      }
    }