Home › Forums › Add-ons › Repeater Field › Advanced Custom Repeater Field Page Navigation › Reply To: Advanced Custom Repeater Field Page Navigation
Hi @chandru998
Thanks for clarifying.
You could accomplish this with some simple PHP. Thinking about it, I would like to create a video tutorial on this topic as it would be a very good demonstration of how to use basic PHP with a repeater field.
Until I create the video, you can write this yourself by using a $_GET parameter in the url to set the ‘page’ number.
eg: ?page=2
In your code, use a variable to hold how many rows per page like so:
$rows_per_page = 5;
Then in your repeater field loop, you can add in a conditional statement like so:
<?php
// vars
$rows_per_page = 5;
$page = 1;
$i = 0;
// read $page from url param
if( !empty($_GET['page']) )
{
$page = $_GET['page'];
}
// vars
$min = $page * $rows_per_page;
$max = $min + $rows_per_page;
if( have_rows('repeater') ):
while( have_rows('repeater') ): the_row(); $i++;
// ignore this row, if $i is lower than $min
if( $i < $min )
{
continue;
}
// stop loop completely, if $i is higher than $max
if( $i > $max )
{
break;
}
// Your loop code
the_sub_field('sub_field');
endwhile;
else :
// no rows found
endif;
?>
Hope that helps.
Thanks
E
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.