Support

Account

Home Forums Add-ons Repeater Field How to limit the records output from a basic repeater loop?

Solved

How to limit the records output from a basic repeater loop?

  • For the basic loop output of a repeater field, how can I limit the amount of records that are output? I want to set a limit of 3.

  • 
    if (have_rows('repeater')) {
      $count = 1;
      while (have_rows('repeater')) {
        the_row();
        // code to show row
        $count++;
        if ($count > 3) {
          break;
        }
      }
    }
    
  • Excellent, thanks John!

  • EDIT –

    It actually is working sorry! It wasn’t displaying for an entirely different reason

    Apologies

    *** original question ***

    Hi John

    I know this solution is really old but is it still valid?

    I am trying to get it to work with a slider using a repeater field from an ACF options page like below but it returns nothing?

    I cant see what I am doing wrong

    <section class="latest-publications">
    
    	<h2>Latest Publications</h2>
    	
    	<div class="pink-divider"></div>
    	<div class="publications-row">
    			
    			<div class="posts-carousel">
    		
    					<?php if (have_rows('publication', 'option' )) {
    					  $count = 1;
    					  while (have_rows('publication', 'option')) {
    						the_row();
    						?>
    						
    						
    								
    						<div class='publication-slide'>
    							
    							
    							<a href="/publications#<?php echo sanitize_title( get_sub_field( 'publication_title' )); ?>" target="_blank"><?php the_sub_field( 'publication_title' ); ?></a></h4>
    							<?php the_sub_field( 'publication_description' ); ?>
    							<p class="icon-date"><?php the_sub_field( 'date' ); ?></p>
    		
    						
    						</div>
    						
    	
    						
    						<?php $count++;
    						if ($count > 3) {
    						  break;
    						}
    					  }
    					}
    				
    				
    				?>
    				
    
    			</div>		
    			
    	</div>		
    </section> 
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.