Home Forums Add-ons Repeater Field Gallery field within a repeater field


Gallery field within a repeater field

  • This might be a silly question but can you have a gallery field within a repeater field?

    I can’t get it to work so will probably use an image repeater field within a repeater field. Just wondering!

  • Hi @belbo_mugins

    Yes, a gallery field will work as a sub field. Perhaps you could better explain what you mean by I can’t get it to work?


  • Hi Elliot!

    Thanks for the reply!

    Yes your right, I had another go and it worked straight away! Must have been having an off day, spent a good hour trying to get it to work but must have missed something obvious (have deleted the code so not sure what I was doing wrong!)

    Working code here incase anyone else gets stuck!

    				// check if the repeater field has rows of data
    				if( have_rows('repeater') ):
    				 	// loop through the rows of data
    				    while ( have_rows('repeater') ) : the_row();
    				        // display a sub field value
    				        $images = get_sub_field('gallery');
    						if( $images ): ?>
    						            <?php foreach( $images as $image ): ?>
    						                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    						            <?php endforeach; 
    				   <?php endwhile;
    				else :
    				    // no rows found
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Gallery field within a repeater field’ is closed to new replies.