Support

Account

Home Forums Add-ons Repeater Field Only loop when certain custom conditions are met and/or loop only once.

Unread

Only loop when certain custom conditions are met and/or loop only once.

  • 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?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.