Support

Account

Home Forums Front-end Issues Can't display gallery images inside flexible content Reply To: Can't display gallery images inside flexible content

  • A simpler version of the problem with clean wordpress install and twentyfourteen theme:
    What I did:

    – Created an about page
    – Assigned the about page to the full width template.
    – Created a new ACF field group assigned to the about page.
    -Added a new flexible content field with slug multicontent.
    – Added a new layout called gallery.
    -Added a Gallery field inside this layout called images.
    – Then added another layout called single_image
    – and finally added inside this layout an image field called image.

    THE CODE:

    
    <?php
    
    // check if the flexible content field has rows of data
    if( have_rows('multicontent') ): // success
    
         // loop through the rows of data
        while ( have_rows('multicontent') ) : the_row();   // success
    
            // check current row layout
            if( get_row_layout() == 'gallery' ):   // success
    
                // check if the nested repeater field has rows of data
                if( have_rows('images') ):   // success
    
                     echo '<ul>';
    
                     // loop through the rows of data
                    while ( have_rows('images') ) : the_row();   // success
    
                        $image = get_sub_field('image');   // Problem! retrieves nothing
    
                        echo '<li><img src="' . $image['url'] . '" alt="' . $image['alt'] . '" /></li>'; // displays the list but with no links even if i remove the ['url'] array parts
    
                    endwhile;
    
                    echo '</ul>';
    
                endif;
    
            elseif( get_row_layout() == 'single_image' ):  // success
    
                $one_image = get_sub_field('image');   // success
    
                echo '<img src="' . $one_image['url'] . '" />';   // success
    
            endif;
    
        endwhile;
    
    else :
    
        // no layouts found
    
    endif;
    
    ?>
    

    THE OUTPUT:

    
    <ul>
    <li><img alt="" src=""></li>
    <li><img alt="" src=""></li>
    <li><img alt="" src=""></li>
    </ul>
    
    <img src="http://localhost/wpsimple/wp-content/uploads/2014/11/foliothumb2.jpg">
    

    I wonder if anyone can replicate this problem or is it just me.
    If there is an obvious mistake in the code above I would appreciate your feedback.