Home › Forums › Front-end Issues › Count total number of post objects › Reply To: Count total number of post objects
Hi John,
Thanks for getting back to me, I tried that and didn’t work the “echo $count = 2” was correct so I used this code;
<?php
$count = count( get_sub_field('featured_developments') );
echo '<strong>The total is '. $count . '</strong></br><br>';
if( have_rows('featured_developments') == 1 ) {
?>
<?php while( have_rows('featured_developments') ): the_row(); ?>
<?php
$post_id = get_sub_field('development', false, false);
?>
<div class="lg-col-12"></div>
<?php $count++; ?>
<?php endwhile; ?>
<?php
} elseif( have_rows('featured_developments') == 2 ) {
echo '2';
?>
<?php while( have_rows('featured_developments') ): the_row(); ?>
<?php
$post_id = get_sub_field('development', false, false);
?>
<div class="lg-col-6 md-col-6"></div>
<?php $count++; ?>
<?php endwhile; ?>
<?php
} else{
?>
<?php while( have_rows('featured_developments') ): the_row(); ?>
<?php
$post_id = get_sub_field('development', false, false);
?>
<div class="lg-col-4 md-col-4"></div>
<?php $count++; ?>
<?php endwhile; ?>
<?php
}
?>
<?php wp_reset_query(); ?>
It outputted “lg-col-12”, when it should’ve outputted “lg-col-6”
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.