If you are using ACF Gallery fields, there’s a quick trick to showing them to the end users by utilizing the existing [gallery] shortcode, which most themes have great support for.
If your field name is “gallery_field”, use this function in your theme where you want to display the gallery:
if(get_field('gallery_field') !== '')
{
$gallery_items_string = '';
foreach(get_field('gallery_field') as $gallery_item)
$gallery_items_string .= $gallery_item['id'] . ',';
echo do_shortcode('[gallery link="file" columns="4" ids="'. $gallery_items_string .'"]');
}
Bonus – Integration with slider plugins:
Now that we’ve integrated with the shortcode, let’s move on to sliders! Below we have an example of an Owl Carousel integration, provided by by Corbin from Commandbase!
$images = get_field('portfolio_gallery');
if( $images ): ?>
<ul class="portfolio-slider">
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>