Home Forums Add-ons Repeater Field Count repeater in a flexible field


Count repeater in a flexible field

  • 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’ ); ?>
    <?php endwhile; ?>

    <?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…

    “Have to make the count before “have_rows””

Viewing 3 posts - 1 through 3 (of 3 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.