I am trying to get pictures from an ACF gallery field to display on another page. I have achieved this with the following code:

<?php $masonry_photos_year = get_field('masonry_gallery_of_the_year', 600);

if( $masonry_photos_year ) :

shuffle($masonry_photos_year); ?>

<div id="full-image" class="white-popup mfp-with-anim mfp-hide">
    <?php foreach ( $masonry_photos_year as $masonry_photo_year ) : ?>
        <div class="full-image-info-wrapper">
          <div class="container-fluid">
            <div class="col-sm-6">
              <?php if( $masonry_photo_year['description'] ) : ?>
                <div class="photo-year">
                  <h3><?php echo esc_html( $masonry_photo_year['description']); ?></h3>
                </div>
              <?php endif; ?>
            </div>
            <div class="col-sm-6">
              <?php if( $masonry_photo_year['caption'] ) : ?>
                <div class="photo-name">
                  <h3><?php echo esc_html( $masonry_photo_year['caption']); ?></h3>
                </div>
              <?php endif; ?>
            </div>
          </div>
        </div>
       <img src="<?php echo $masonry_photo_year['sizes']['post-xlarge'] ?>" class="img-responsive" alt="<?php echo $masonry_photo_year['alt']; ?>">
   <?php endforeach; ?>
 </div>

Now, the images are displaying on the new page but most of the times the same image displays twice in a row. So I am guessing shuffle() is not the best option here. Ideally this would not happen and once a user sees one of these images when visiting the site if they thenavigate to another page and then to this page again I don’t want any image to display again. So each user would see a different image every time they visit the site and only once.

How could I implement this functionality?

Read more here: Advanced Custom Fields – Get image from gallery field from other page and display randomly


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: