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!
There isn’t any easy way to programmatically sort the rows of a repeater.
ACF has an example of using array_multisort().
There are other PHP functions as well, I generally prefer using usort().
You must be logged in to reply to this topic.
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.