Support

Account

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,