0

Anyone got any ideas why this counter will not count in the id for the h4 tag?

<?php           
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();

//Do something if a specific array value exists within a post
$clauses = wp_get_post_terms($post->ID, $section->taxonomy, array("fields" => "all"));
$counter3 = 0; 
foreach($clauses as $clause) { ?>
<h4 class="<?=($clause->parent == 0) ? 'd-none' : '' ?>" id="<?php echo $counter3; ?>"><?php echo $clause->name; ?></h4>
<a class="d-block" href="<?php echo the_permalink();?>"><?php echo the_title(); ?></a>                                          
<?php $counter3++; }?>

<?php endwhile; endif; wp_reset_query(); ?>

Any help appreciated.

CHRIS

1 Answers1

0

Please put

$counter3 = 0; 

before the loop start;

the code should be like this:

 <?php           
    if ( $loop->have_posts() ) : 
 $counter3 = 0; 
while ( $loop->have_posts() ) : $loop->the_post();

    //Do something if a specific array value exists within a post
    $clauses = wp_get_post_terms($post->ID, $section->taxonomy, array("fields" => "all"));

    foreach($clauses as $clause) { ?>
    <h4 class="<?=($clause->parent == 0) ? 'd-none' : '' ?>" id="<?php echo $counter3; ?>"><?php echo $clause->name; ?></h4>
    <a class="d-block" href="<?php echo the_permalink();?>"><?php echo the_title(); ?></a>                                          
    <?php $counter3++; }?>

    <?php endwhile; endif; wp_reset_query(); ?>
Rajkumar Gour
  • 1,131
  • 12
  • 26