Support

Account

Home Forums ACF PRO Row count needed in flexible content > layout > repeater

Solved

Row count needed in flexible content > layout > repeater

  • I have tried everything I can find including

    $count = count( get_field(‘highlight’) )
    $count = count(get_sub_field(‘highlight’))

    I have a landing template for all the flexible content

    if( have_rows('landing_page_content') ) { ?>
    
    <section class="landing-content">
    <?php while ( have_rows('landing_page_content') ) : the_row();
    	if( get_row_layout() == 'hero' ) { ?>
    	<?php include('partials/blocks/hero');?>
    	<?php }
    
    else if( get_row_layout() == 'highlights' ) { ?>
    	<?php $count = count(get_sub_field('highlight'));?>
    	<?php include('partials/blocks/highlight.php');?>
    	<?php }
    
    etc....

    The basic of the highlights row includes

    ?php elseif ( get_row_layout() == 'highlights' ) : ?>
    			<?php the_sub_field( 'headline' ); ?>
    			<?php if ( have_rows( 'highlight' ) ) : ?>
    				<?php while ( have_rows( 'highlight' ) ) : the_row(); ?>
    					<?php the_sub_field( 'large_text' ); ?>
    					<?php the_sub_field( 'small_text' ); ?>
    				<?php endwhile; ?>
    			<?php else : ?>
    				<?php // no rows found ?>
    			<?php endif; ?>

    I need the count of highlight. What am I doing wrong?

  • <?php if ( have_rows( 'highlight' ) ) :
      $repeater = get_field('highlight'); 
      while ( have_rows( 'highlight' ) ) : the_row();
        if (!empty($repeater)) {
          $count = count($repeater);
        };
    endwhile;
    endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.