Home › Forums › ACF PRO › Get title of next row in slick slider › Reply To: Get title of next row in slick slider
there isn’t a direct way to get the next item inside of a repeater have_rows() loop, but it can be done inderectly, but this will only work for simple fields.
while (have_rows('home-slider')) {
the_row();
// maybe get a text field from the next row
$index = get_row_index();
$next_title = get_post_meta($post->ID, 'home-slider_'.$index.'hero-title', true);
}
If I needed a way to look ahead into repeaters, or backwards for that matter I would skip the have_rows() loop and just get the repeater as an array so that I can look at whatever I need to.
// returns an array, each element is a row of the repeater
$slides = get_field('home-slider');
if (!empty($slides)) {
foreach ($slides as $index => $slide) {
$title = $slider['hero-title'];
$next_title = '';
if (isset(slides[$index+1])) }
$next_title = $slides[$index+1]['hero-title'];
}
}
}
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.