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!
ποΈ Just one more day until the next session of ACF Chat Fridays! Make sure to register for the latest updates on whatβs coming in ACF 6.1!
— Advanced Custom Fields (@wp_acf) March 30, 2023
π Friday 31st March 3pm UTC
π Register here - https://t.co/3UtvQbDwNm pic.twitter.com/7xtEJakeQN
© 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.