Hi,
I’d like to count the number of repeater field (wich is in a flexible content). the goal is to set the correct class for bootstrap columns.
Actually, this return only “1” when I echo the count number.
<?php elseif ( get_row_layout() == ‘bloc_image_centrale’ ) : ?>
<?php if ( get_sub_field( ‘image-bloc_image_centrale’ ) ) { ?>
” />
<?php } ?>
<?php if ( have_rows( ‘colonnne’ ) ) :?>
<div class=”w-row”>
<?php while ( have_rows( ‘colonnne’ ) ) : the_row();
$number_of_cols = count( get_sub_field( ‘colonnne’ ) );
$classcol = 12 / $number_of_cols ;
?>
<div class=”w-col w-col-<?php echo $classcol; ?>”>
<?php the_sub_field( ‘titre’ ); ?>
<?php the_sub_field( ‘contenu’ ); ?>
</div>
<?php endwhile; ?>
</div>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
I am also having this exact issue. I have a flexible content field and one of the options is a repeater. I want to know how many items are in the repeater in order to set a class, but it’s returning “1” instead of what should be “2” or “3.”
When you find your own confirmation of the solution from the same problem 6 months ago…
https://support.advancedcustomfields.com/forums/topic/count-repeater-items/
“Have to make the count before “have_rows””