0

I tried to get ACF repeater from the group field. I must be blind, but I cannot find a mistake inside my code.

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

        <?php if( have_rows( 'acf_repeater' ) ): ?>
    
        <ul>
    
            <?php while( have_rows( 'acf_repeater' ) ): the_row();
                
                $link_text = get_sub_field( 'acf_repeater_field_text' );
                $link_url = get_sub_field( 'acf_repeater_field_url' );
            ?>
    
            <li>
                <a href="<?php echo $link_url; ?>"><?php echo $link_text; ?></a>
            </li>

            <?php endwhile; ?>
            
        </ul>

        <?php endif; ?>

    <?php endwhile; ?>

<?php endif; ?>
2
  • I think that there is no issue in your code. so please check the acf structure. Did you test that acf_group data is got?
    – WebKing
    Commented Jun 21, 2022 at 20:42
  • @WebKing Yes, I also tried this code which works. But I want to find my mistake in the code above. code<?php if ( have_rows( 'acf_group' ) ) { while ( have_rows( 'acf_group' ) ) { the_row(); if ( have_rows( 'acf_repeater' ) ) { echo '<ul>'; while ( have_rows( 'acf_repeater' ) ) { the_row(); $link_text = get_sub_field( 'acf_repeater_field_text' ); $link_url = get_sub_field( 'acf_repeater_field_url' ); printf( '<li>%s: %s</li>', $link_text, $link_url ); } echo '</ul>'; } } } ?>code
    – Jirka
    Commented Jun 22, 2022 at 9:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.