I can’t figure out why my ACF gallery is only showing the first image (I have 3 selected in the backend)
`
<?php
// Load value (array of ids).
$image_ids = get_field(‘event_gallery’);
if( $image_ids ) {
// Generate string of ids (“123,456,789″).
$images_string = implode( ‘,’, $image_ids );
// Generate and do shortcode.
// Note: The following string is split to simply prevent our own website from rendering the gallery shortcode.
$shortcode = sprintf( ‘[‘ . ‘gallery ids=”%s”]’, esc_attr($images_string) );
echo do_shortcode( $shortcode );
}
$size = ‘full’; // (thumbnail, medium, large, full or custom size)
if( $images ): ?>
<?php foreach( $images as $image_id ): ?>
-
<?php echo wp_get_attachment_image( $image_id, $size ); ?>
<?php endforeach; ?>
<?php endif; ?>
‘
I’m not sure I follow what you’re code is trying to do, but try this and see if it gets you the result you need:
<?php
$gallery = get_field('event_gallery');
?>
<div>
<ul>
<?php foreach( $gallery as $image ): ?>
<li>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
</li>
<?php endforeach; ?>
</ul>
</div>
Just make sure your field returns format as image array.
Are you trying to use the wp gallery shortcode or show the images in a loop?
These are 2 different things.
I just noticed my images actually aren’t saving on the backend. Only one photo saves, even when I try to add more to the gallery. Hmmmm….