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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.