Support

Account

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