Support

Account

Home Forums Add-ons Repeater Field Previous and next field in repeater Reply To: Previous and next field in repeater

  • Hi

    You can try something like this with the index when you are doing the foreach loop:

    
    <?php
    
    $repeater = get_field('repeater_name');
    $repeaterCount = count($repeater);
    
    foreach ($repeater as $index => $row) {
        // if it's not the first row, that means we have a previous row
        $previousRow = $index == 0? null : $repeater[$index - 1];
    
        // if it's not the last row, that means we have a next row
        $nextRow     = $index == ($repeaterCount - 1)? null : $repeater[$index + 1];
    
        ... code
    }
    

    Cheers