I have a register form which is build with flexible content.
The first while loop, loops through flexible content elements.
The second loop (which is inside the first loop) is looping through a repeater field, and within the while loop there is another repeater field with it’s own loop (the third loop).
(The second loop will loop 3 times on my website because of the content I added in ACF fields in WordPress).
The third loop produces a list of hyperlinks. The third loop will loop 4 times to get all the links.
Now here comes the tricky part:
– I want to have a condition surrounding the third loop, to produce links only once. (at the moment without the condition, it will loop 3 times which results in creating 12 links instead of 4). (Maybe a dynamic counter of some sort is part of the answer?).
– Then when the ‘second loop’ runs for a second time, the third loop skips the first results of the loop (the first 4 links) and fetches the results row after that, and than stops/breaks the (third) loop, producing another 4 fresh links.
– When the second loop runs a for a third time, it should again fetch the results row thereafter from the previous loop (just like above). etc.
Yes, I know it’s confusing, but I really need this.
My code at the moment:
<?php
if (have_rows('register_form')) :
while (have_rows('register_form')) : the_row();
if( have_rows('paginas_stappen') ): ?>
<div>
<ul class="tab-link-list">
<?php
while ( have_rows('paginas_stappen') ) : the_row();
$order_number = 1;
while (have_rows('hyperlinks_in_kop_pagina')) : the_row(); ?>
<li>
<div class="order-number <?php echo get_sub_field('uitgelichte_link') == 'yes' ? 'highlighted' : ''; ?>">
<?php echo $order_number; ?>
</div>
<a onclick="goToTab(<?php echo get_sub_field('link_gaat_naar_pagina') - 1; ?>)">
<?php the_sub_field('link_tekst'); ?>
</a>
</li>
<?php
$order_number++;
endwhile;
endwhile; ?>
</ul>
</div>
<?php endif;
<?php endwhile; endif; ?>
I’ve been struggling with this for a long of time now.
Is something like this possible with ACF or is there another way to achieve this?