Home Forums Add-ons Gallery Field Gallery Field inside a Repeater field


Gallery Field inside a Repeater field

    • raonip

    • June 27, 2014 at 8:54 am

    Hi, I have two Gallery Fields.
    One outside a repeater field and another inside.

    With this code below from your Gallery Documentation ( my Gallery works fine. This Gallery Field is OUTSIDE a Repeater Field:

        $galeriafotosimage_ids = get_field('galeria_de_fotos', false, false);
        $shortcode = '[portfolio_slideshow slideheight=310 include="' . implode(',', $galeriafotosimage_ids) . '"]';
        echo do_shortcode( $shortcode );

    But this Gallery Field below, that is inside a Repeater Field does not work.
    This code is inside a Repeater Loop.

        $image_ids = get_field('fotos_da_obra', false, false);
        $shortcode2 = '[portfolio_slideshow slideheight=310 include="' . implode(',', $image_ids) . '"]';
        echo do_shortcode( $shortcode2 );

    When I use the code Above I have this Error in my Page:
    Warning: implode() [function.implode]: Invalid arguments passed in /home/storage/0/7f/ab/site1372268450/public_html/wp-content/themes/costa-hirota/single-empreendimentos.php on line 244

    Do you know How can I make it work when Gallery field is inside a Repeater field???

    Thanks very much!!

    • raonip

    • June 27, 2014 at 8:56 am

    HI again,

    I have Also tried with get_sub_field, but not working:

        $image_ids = get_sub_field('fotos_da_obra', false, false);
        $shortcode2 = '[portfolio_slideshow slideheight=310 include="' . implode(',', $image_ids) . '"]';
        echo do_shortcode( $shortcode2 );
  • I have the same problem… anyone have a solution?

  • I have the same issue as well.

    • raonip

    • November 4, 2014 at 9:19 pm

    Please!!! Anyone can help with this issue!?

  • well, it’s incredible that i’d payed for this plugin and this feature is not available. please give response to this issue, thanx

  • I figured it out. Here’s how to use galleries inside a repeater field:

    BASIC TIP: Do not use “get_field” or “the_field” inside a repeater. Instead use “the_sub_field” and “get_sub_field” instead.

    The following code will work assuming you:

    – Created a repeater called “gallery-repeater”.
    – Created a text field inside that repeater called “gallery-name”.
    – Created a gallery inside that repeater called “gallery-images”.

    <!-- CHECK OUT REPEATER "gallery-repeater" -->
    <?php if( have_rows('gallery-repeater') ): ?>
       <?php while ( have_rows('gallery-repeater') ) : the_row(); ?>
         <?php the_sub_field('gallery-name'); 
         $images = get_sub_field('gallery-images'); 
         if( $images ):?>
            <?php foreach( $images as $image ): ?>
    	   <a href="<?php echo $image['url']; ?>">
    	      <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
               <p><?php echo $image['caption']; ?></p>
            <?php endforeach; ?>
         <?php endif; 
    else :
    // no rows found
    endif; ?>

    It’s not styled so it’s really bare.

    ! Careful not to mix up PHP (if then else) code and HTML code.

  • I also tried with “get_sub_field” but no luck. Code posted above didn’t work for me as well.

    Anybody has solution?

  • <?php if( have_rows('gallery') ): ?>
    <?php while ( have_rows('gallery') ) : the_row(); ?>
    <h2 class="gallery-h2"><?php the_sub_field('gallery_description'); ?></h2>
    <?php $images = get_sub_field('gallery_pics');
    if( $images ): ?>
    <?php foreach( $images as $image ): ?>
    <div class="box">
    <a class="boxInner" href="<?php echo $image['url']; ?>" data-lightbox-gallery="<?php the_sub_field('gallery_group'); ?>">
    <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
    <?php endforeach; ?>
    <div class="hr"></div>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php else : ?>
    // no images found
    <?php endif; ?>

    I combined repeater together with gallery and it works like charm.

    • rozuja

    • December 16, 2019 at 12:33 am

    Don’t be mad its working a charm. Used this with OWL Carousel 2, really good.

    Only posting the PHP so you can grab it.

    // check if the repeater field has rows of data
    if( have_rows('repetidor_imagenes') ):
      // loop through the rows of data
        while ( have_rows('repetidor_imagenes') ) : the_row();
    // Start Loop
    // Grab the subfield gallery array
    //(Use the array return on ACF backend panel, you will have more control con the atts)
    $images = get_sub_field('geleria_de_imagenes');
    if( $images ):
    $output .= '<div class="vc_row wpb_row vc_row-fluid prodvar imgal-container">';
    $output .= '<div class="owlonlyfix owl-carousel owl-theme">';
      foreach( $images as $image ):
        $output .= '<div class="item imgal-img"><img src="'.$image['sizes']['thumbnail'].'" alt="'.$image['alt'].'" class="imgal-img" /></div>';
    $output .= '</div></div>'; 
    // End Loop
    else :
        // no rows found
    endif; ?>


Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Gallery Field inside a Repeater field’ is closed to new replies.

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.