Support

Account

Home Forums ACF PRO Adding manual page breaks on repeater field Reply To: Adding manual page breaks on repeater field

  • This is basically functionality that you’ll need to custom build, but it is possible. I just did something similar where every row in a repeater field is a separate page on the front end.

    What I did was to create a loop that shows page links, similar to the page links that WP shows. I had to generate the page links /1, /2, /3, etc. Then in the page code I tested to see which of the repeater rows should be displayed and then looped through the repeater till it got to the right one and showed it.

    This isn’t something that ACF will do for you.

    Here is some code that might help you get it going. just some of what I used.

     
    // get the page number
    $page = 0;
    $base_url = $_SERVER['REQUEST_URI']
    if (preg_match('#/([0-9]+)/?$#', $_SERVER['REQUEST_URI'], $matches)) {
      $page = intval($matches[1]);
      $base_url = preg_replace('#[0-9]+/?$#', '', $base_url);
    }
    
    // output page links
    $count = intval(get_post_meta($post->ID, 'repeater', true));
    if ($count) {
      ?>
        <ul>
          <?php 
            for ($i=0; $i<$count; $i++) {
              ?>
                <li><a href="<?php 
                  echo $base_url,$i,'/'; ?>><?php 
                  echo $i; ?></a></li>
              <?php 
            }
          ?>
        </ul>
      <?php 
    }
    
    // output the right row
    $count = 0;
    if (have_rows($repeater)) {
      while (have_rows($repeater)) {
        $count++;
        the_row();
        if ($count == $page) {
          // output the content of this row
        }
      }
    }