Home › Forums › General Issues › Getting a count of repeater sub fields › Reply To: Getting a count of repeater sub fields
Something like this? 🙂
<?php if( have_rows('questions') ): ?>
<?php $counter = 1; //this sets up the counter starting at 0 ?>
<ul class="questions-answers">
<?php while( have_rows('questions') ): the_row(); ?>
<li><h3><a href="#"><?php the_sub_field('question_text'); ?></a></h3>
<p class="class_<?php echo $counter; // Prints the number of counted row ?>"><?php the_sub_field('answer_text'); ?></p>
<p><?php the_sub_field('answer_text'); ?></p></li>
<?php $counter++; // add one per row ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.