Home › Forums › General Issues › Count total amount of flexible content used? › Reply To: Count total amount of flexible content used?
Hi there,
Here, you’re calculating a new count at each loop.
By default a $variable will reset at each loop’s iteration.
To calculate all iterations, you’ll need to concatenate your counter and you increment it at the end of each loop.
Please, try something like this:
<?php global $post; foreach ( $groups as $term_id => $posts ) { $term = get_term( $term_id );?>
<?php foreach ( $posts as $post ) { setup_postdata( $post ); ?>
<?php if( have_rows('irl_today_data') ):?>
<?php $count = 0;
while ( have_rows('irl_today_data') ) : the_row();
$acf_loop_count .= $count; //Continue your count at each loop
?>
<?php if( get_row_layout() == 'irl_today_website' ):?>
<?php endif;?>
<?php if( get_row_layout() == 'irl_today_social_media' ):?>
<?php endif;?>
<?php echo $acf_loop_count; //Echo inside the loop to output your counter at each loop (4 5 6) ?>
<?php $count++; endwhile;?>
<?php echo $acf_loop_count; //Echo outside the loop to output your final value (6) ?>
<?php endif;?>
<?php endif; ?>
<?php } } wp_reset_postdata();?>
Let me know if it helps,
RemSEO
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.