Support

Account

Home Forums Add-ons Repeater Field Pagination on an Advanced Custom Fields Repeater Stopped Working

Solving

Pagination on an Advanced Custom Fields Repeater Stopped Working

  • Not sure if this was since upgrading to PHP 7.2 or the latest WordPress version but the following code used to allow me to add pagination for repeater values. Now what seems to happen is that the page just reloads the page. The pagination link shows as /example/2/, this used to load the page but now it is just reloading example.

    Any ideas?

    <?php
    /*
    * Paginatation on Advanced Custom Fields Repeater
    */

    if ( get_query_var(‘paged’) ) {
    $page = get_query_var(‘paged’);
    } elseif ( get_query_var(‘page’) ) {
    $page = get_query_var(‘page’);
    } else {
    $page = 1;
    }

    // Variables
    $row = 0;
    $images_per_page = 10; // How many images to display on each page
    $images = get_field( ‘image_gallery’ );
    $total = count( $images );
    $pages = ceil( $total / $images_per_page );
    $min = ( ( $page * $images_per_page ) – $images_per_page ) + 1;
    $max = ( $min + $images_per_page ) – 1;

    // ACF Loop
    if( have_rows( ‘image_gallery’ ) ) : ?>

    <?php while( have_rows( ‘image_gallery’ ) ): the_row();

    $row++;

    // Ignore this image if $row is lower than $min
    if($row < $min) { continue; }

    // Stop loop completely if $row is higher than $max
    if($row > $max) { break; } ?>

    <?php $img_obj = get_sub_field( ‘image’ ); ?>
    “>
    ” alt= “Your ALT Tag” />

    <?php endwhile;

    // Pagination
    echo paginate_links( array(
    ‘base’ => get_permalink() . ‘%#%’ . ‘/’,
    ‘format’ => ‘?paged=%#%’,
    ‘current’ => $page,
    ‘total’ => $pages
    ) );
    ?>

    <?php else: ?>

    No images found

    <?php endif; ?>

  • Bumping an older topic, but I am also having this issue. This solution to add pagination to a repeater field was previously recommended on the ACF forums. I would really like to get it working again. I believe I’ve had this issue since the WordPress 5.5 update, as I was already using php 7.3 when I first implemented this.

    Post here: https://support.advancedcustomfields.com/forums/topic/advanced-field-repeater-pagination-with-custom-post/

    https://jonathannicol.com/blog/2014/03/06/paginating-an-advanced-custom-fields-repeater/

  • I do not see anything in the original article that should not work with the current versions of WP and ACF

  • I can verify that this works on WP 5.4, and NOT on 5.5. I’ve just tested it on two different sites and rolling back to 5.4 makes it work. I can’t figure out where the break is though.

  • Fix below. Working with WordPress 5.8:

    Default WordPress permalink pagination structure is /example/page/number/, so You should change ‘base’ variable to:
    ‘base’ => get_permalink() . ‘page/%#%’ . ‘/’,

    After that You can go to WordPress -> Settings -> Permalinks and click save to refresh permalinks structure.

    You will see working pages which load correct fields with pages structure as:
    /example/page/2/, /example/page/3/ ….

  • I came across this pagination for a new project I’m working on, which is exactly what I need. But its not paging to the next page.

    Is this something that got affected with WordPress 6? I’ve attempted the fix mentioned by majk86 that worked for 5.8 but its not working for me!

  • On WP 6.0.1 pagination works fine – BUT no drag & drop.
    Can they coexist?

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.