Home › Forums › ACF PRO › New Attachment Field – Update images › Reply To: New Attachment Field – Update images
Hi James,
Thanks or your reply. However having had a few attempts I’m ot sure I fully understand what I need to do.
I have a gallery on some certain page tmeplates and in a custom post type.
<?php //Gallery images
$images = get_field('image_gallery');
$size = 'full';
if( $images ): ?>
<div id="masonry-loop">
<div class="grid-sizer"></div>
<div class="gutter-sizer"></div>
<?php foreach( $images as $image ): ?>
<img class="grid-entry" src="<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach; ?>
</div>
<?php endif; ?>
Do I work the update_field into the gallery loop?
For example:
<?php //Gallery images
$images = get_field('image_gallery');
$size = 'full';
$count = (int) get_field('field_59b6acbe2a8g6');
if( $images ): ?>
<div id="masonry-loop">
<div class="grid-sizer"></div>
<div class="gutter-sizer"></div>
<?php foreach( $images as $image ): ?>
// increase
$count++;
// update
update_field('field_59b6acbe2a8g6', $count);
<img class="grid-entry" src="<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach; ?>
</div>
<?php endif; ?>
If so I can’t seem to get it to work.
Any pointers would be greatly appreciated.
Many thanks,
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.