Support

Account

Home Forums ACF PRO Sorting gallery images inside a repeater

Unread

Sorting gallery images inside a repeater

  • Hello!

    Some years ago I used code from this thread:
    https://support.advancedcustomfields.com/forums/topic/gallery-field-inside-a-repeater-field/

    and modified it into a way I needed it, which is a bunch of galleries on tabs:

    <div class="tabs">
    		<?php if( have_rows('galleries') ):
    		$i = 0;?>
    				
    					<div class="row m-2">
    					<div class="col-md-12 content-area text-center">
    					<ul class="gallery-menu tab-links">
    					<?php while ( have_rows('galleries') ) : the_row(); ?>
    						<?php
    						$gallery_title_name = "repeater_gallery_title";
    						$gallery_title = get_sub_field_object($gallery_title_name); ?>
    						<li><a href="#tab-<?php echo str_replace(' ', '', get_sub_field('repeater_gallery_title')); ?>"><?php the_sub_field('repeater_gallery_title'); ?></a></li>
    					<?php endwhile; ?>
    					</ul>
    					</div>
    					</div>
    					<div class="tab-content">
    					
    					<?php while ( have_rows('galleries') ) : the_row(); $i++; ?>
    					<?php $images = get_sub_field('repeater_gallery');
    					
    					if( $images ): ?>
    					
    					<div id="tab-<?php echo str_replace(' ', '', get_sub_field('repeater_gallery_title')); ?>" class="tab <?php 
    					  if ($i == 1) {
    						?>active<?php 
    					  }
    					?>">
    					<div class="row m-2">
    					<div class="col-md-12 content-area text-center">
    						<h3><?php the_sub_field('repeater_gallery_title'); ?></h3>
    					</div>
    					</div>
    					<div class="row d-flex justify-content-center mt-2 mb-4 gallery">
    					<?php foreach( $images as $image ): ?>
    
    					<div class="col-md-3 text-center gallery-item">
    
    					<a href="<?php echo $image['url']; ?>" data-lightbox-gallery="<?php the_sub_field('galleries'); ?>">
    
    					<img src="<?php echo $image['sizes']['thumbnail']; ?>" class="p-2" alt="<?php echo $image['alt']; ?>" />
    
    					</a>
    
    					</div>
    
    					<?php endforeach; ?>
    					</div>
    					</div>
    					
    					<?php endif; ?>
    					
    					<?php endwhile; ?>
    					</div>
    					<?php else : ?>
    
    					// no images found
    
    		<?php endif; ?>
    		</div>

    Is it possible to adjust the sort order with the above code? I know with a WP Query I could write some args but not sure where I’d start with this. Any help would be appreciated. Thanks!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.