Home › Forums › ACF PRO › New Attachment Field – Update images › Reply To: New Attachment Field – Update images
I just replied but it seems to have vanished.
Thanks for your reply, however after a few attempts I’m stuck and not sure where to place the foreach loop you mention.
I have a galley (I’ve stripped back the code here)
<?php //Gallery images
$images = get_field('image_gallery');
$size = 'full';
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<img class="grid-entry" src="<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach; ?>
<?php endif; ?>
Could I weave the the update_field into that foreach loop?
Or does it need to be somewhere else?
e.g.
<?php //Gallery images
$images = get_field('image_gallery');
$size = 'full'; //
$count = (int) get_field('field_59b6acbe2a8d2');
if( $images ): ?>
<?php foreach( $images as $image ):
// increase
$count++;
// update
update_field('field_59b6acbe2a8d2', $count); ?>
<img class="grid-entry" src="<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach; ?>
<?php endif; ?>
Once that is working, does it only take a refresh of the page for it to update the images?
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βre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.