Support

Account

Home Forums Add-ons Repeater Field Repeater field off by one.

Solved

Repeater field off by one.

  • I’m using the repeater field extensively throughout my site and in the back end if I enter 6 values (or any arbitrary value) into that repeater field, I will see 6 values, as expected. If I check the database there are also 6 entries that I can see. However,
    when I use my while loop to on the front end it is always off by one. I.e. I will only see 5 of my 6 entries. Here is my code:

    <h2 class="reach-title"><?php the_sub_field('reach_title');?></h2>
    <p class="reach-subtitle"><?php the_sub_field('reach_subtitle');?></p>
    
    <?php if ( have_rows('reach_stat') ) : the_row(); ?>
    
    	<?php while ( have_rows('reach_stat') ) : the_row(); ?>
    
    		<?php $reach_item_logo = get_sub_field('reach_item_logo'); ?>
    
    		<pre>
    		<?php var_dump($reach_item_logo);?>
    		</pre>
    
    		<div class="reach-stat">
    			<img class="reach-item-logo" src="<?php echo $reach_item_logo['url'];?>" alt="<?php echo $reach_item_logo['alt'];?>">
    			<p class="reach-item-stat"><?php the_sub_field('reach_item_stat'); ?></p>
    			<p class="reach-item-sub-text"><?php the_sub_field('reach_item_sub_text'); ?></p>
    		</div>
    
    	<?php endwhile; ?>
    
    <?php endif; ?>

    Using ACF Pro 5.2.6 and WordPress 4.2.2

  • After further testing, it is always the first field of the repeater that doesn’t display, in case that helps narrow down the problem.

  • Hi @acha5066 ,

    Try removing the_row() from after the if-statement.

  • Thanks Jonathan, I actually came back here to close this thread because I noticed that but you beat me to it. Cheers!

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

The topic ‘Repeater field off by one.’ is closed to new replies.