Home › Forums › Add-ons › Gallery Field › Gallery Field inside a Repeater field
Hi, I have two Gallery Fields.
One outside a repeater field and another inside.
With this code below from your Gallery Documentation (http://www.advancedcustomfields.com/resources/field-types/gallery/) my Gallery works fine. This Gallery Field is OUTSIDE a Repeater Field:
<?php
$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.
<?php
$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!!
HI again,
I have Also tried with get_sub_field, but not working:
<?php
$image_ids = get_sub_field('fotos_da_obra', false, false);
$shortcode2 = '[portfolio_slideshow slideheight=310 include="' . implode(',', $image_ids) . '"]';
echo do_shortcode( $shortcode2 );
?>
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') ): ?>
<!-- CHECK TO SEE IF IT HAS ROWS IN IT -->
<?php while ( have_rows('gallery-repeater') ) : the_row(); ?>
<!-- DISPLAY THE TEXT-FIELD THEN ASSIGN OUR GALLERY TO VARIABLE $images -->
<?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']; ?>" />
</a>
<p><?php echo $image['caption']; ?></p>
<?php endforeach; ?>
<?php endif;
endwhile;
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']; ?>" />
</a>
</div>
<?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.
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>';
endforeach;
$output .= '</div></div>';
endif;
// End Loop
endwhile;
else :
// no rows found
endif; ?>
Cheers!!!
The topic ‘Gallery Field inside a Repeater field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.