Support

Account

Home Forums Add-ons Repeater Field Get value from next row in repeater Reply To: Get value from next row in repeater

  • Getting the previous and next row would depend on what you want to do at the ends of the row. For example, if the current row is the first row of the repeater do you want to show nothing for previous or do you want to show the last row?

    The first think you need to know in your loop is the current index, you do that by adjusting the loop

    
    foreach( $blocks as $index => $block ) :
    

    Next it depends on what you want to do. To show nothing before and after at the beginning/end

    
    // previous row
    if ($index > 0) {
      $previous_row_value = $blocks[$index-1]['field_name'];
    }
    
    // next row
    if ($index+1 < count($blocks)) {
      $next_row_value = $blocks[$index+1]['field_name'];
    }
    

    if you want to have a continuous loop then you need to calculate the next and previous index

    
    $prev_index = $index - 1;
    if ($prev_index < 0) {
      $prev_index = count($blocks)-1;
    }
    
    $next_index = $index + 1;
    if ($next_index >= count($blocks)) {
      $next_index = 0;
    }