phpwordpresswhile-loopnested-loopsadvanced-custom-fields

Repeater inside Group ACF Wordpress


I'm using Advanced Custom Fields for Wordpress and trying to loop a repeater inside a group. All I get is "Notice: Array to string conversion in..."

What's wrong & how do I fix it?

<?php if( have_rows('start_horlurar') ): while ( have_rows('start_horlurar') ) : the_row();  ?>

<?php $horlur = get_sub_field('horlur'); ?>

<?php if( have_rows( $horlur['arsmodeller_lankar']) ): while ( have_rows($horlur['arsmodeller_lankar']) ) : the_row();  ?>

<?php echo get_sub_field('lank'); ?>

<?php endwhile; endif; ?>

<?php endwhile; endif; ?>

Solution

  • In nested ACF Repeaters, you need not to add the reference of parent repeater - just add the repeater name alone. Try like this.

    <?php
    if( have_rows('start_horlurar') ): while ( have_rows('start_horlurar') ) : the_row(); 
        echo get_sub_field('horlur');
        if( have_rows('arsmodeller_lankar') ): while ( have_rows('arsmodeller_lankar') ) : the_row(); 
            echo get_sub_field('lank');
        endwhile; endif;
    endwhile; endif;
    ?>
    

    UPDATED CODE: You need to loop the ACF Group field too like ACF Repeater. Try like this.

    <?php
    if( have_rows('start_horlurar') ): while ( have_rows('start_horlurar') ) : the_row(); 
        if( have_rows('horlur') ): while ( have_rows('horlur') ) : the_row();       
            if( have_rows('arsmodeller_lankar') ): while ( have_rows('arsmodeller_lankar') ) : the_row(); 
                echo get_sub_field('lank');
            endwhile; endif;
        endwhile; endif;
    endwhile; endif;
    ?>