Support

Account

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”