ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]

It’s not in the documentation mainly because it’s an internal function, they weren’t expecting you to use or need it.

have_rows() checks to see whether there is a currently active loop- if not, it creates a global with your repeater rows; if so, it picks up where you left off- then it lets you know whether there are rows remaining to be looped through. Your example is intriguing, seems to be a bit of a fringe scenario, but I can see how frustrating it would be. After jumping out of the loop midstream, you aren’t automatically returned to the beginning because the previous loop is still active and has rows remaining.

ACF doesn’t have a true rewind_posts() equivalent, but you can either run the reset_rows() function or the function it’s wrapping: acf_remove_loop() (also internal and undocumented, sorry!). Whichever you use should probably be run right before your break though, so you don’t end up with unexpected results from your if ( have_rows() ) should you ever be removing the last row and following it up with another loop.

An unrelated but interesting tidbit is that you actually don’t need the custom row counter, they provide get_row_index() for just this purpose.

Leave a Comment