I have loop in WordPress and I am trying to get increment values for IDs, my code looks like this:
<?php if(get_field('repeater_field_name')): $i = 0; ?>
<ul>
<?php while(has_sub_field('repeater_field_name')): $i++; ?>
<li class="HR-<?php echo $i; ?>">
sub_field_1 = <?php the_sub_field('sub_field_1'); ?>, sub_field_2 = <?php the_sub_field('sub_field_2'); ?>, etc
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
This code gives me an output like this:
<li class="HR-1"></li>
What am trying to achieve is output like this:
<li class="HR-01"></li>
An know that I can add 0 but then the output will be like this:
<li class="HR-010"></li>
IDs from 0-9 needs to be like this:
<li class="HR-01"></li>
<li class="HR-02"></li>
IDs from 10 needs to be like this:
<li class="HR-10"></li>
<li class="HR-11"></li>
Can anybody try to help me with this?