ACF Image in Repeater not working

For a custom WP theme I am creating I am using ACF. I need to have a repeater that outputs images. I have it set to image object and using the correct code. In fact I tried it without a repeater and it works perfectly. Its only within the repeater that it fails.

                <div class="row col-md-12">
                <?php

                // check if the repeater field has rows of data
                if( have_rows('pics') ):

                    // loop through the rows of data
                    while ( have_rows('pics') ) : the_row();

                        // display a sub field value
                ?><div class="col-md-4">

                    <?php 

                    $image = get_field('img');

                    if( !empty($image) ): ?>

                        <img src="<?php echo $image; ?>" alt="<?php echo $image['alt']; ?>" />

                    <?php endif; ?>
                </div> <?

                    endwhile;

                else :

                    // no rows found

                endif;

                ?>
            </div>

What is causing the image data to not loop?

Related posts

Leave a Reply

2 comments

  1. I think this is what you have to do:

    <?php
    
    // check if the repeater field has rows of data
    if( have_rows('img') ):
    
        // loop through the rows of data
        while ( have_rows('img') ) : the_row();
    
            // display a sub field value
            $image = get_sub_field('sub_img'); ?>
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
        <?php endwhile;
    
    else :
    
        // no rows found
    
    endif;
    
    ?>
    

    This is assuming that you are outputting an image object and not a url in your ACF settings.