Support

Account

Home Forums Add-ons Gallery Field Add a unique field for each image in the gallery

Solved

Add a unique field for each image in the gallery

  • Hello,
    I try to add a “photographer” field for each photo in the gallery.
    in ACF I created a photographer field attached to the media.
    For each photo, the “photographer” field is displayed correctly.
    But in my code impossible to display the unique “photographer” field for each photo in the gallery.
    Here is my code, thanks a lot for the help

    
    <?php
                while (have_posts()) : the_post();
                   
                ?>
    
                    <?php
    
                    $images = get_field('gallery');
    
                    if ($images) : ?>
                        <div>
                            <?php foreach ($images as $image) : ?>
    
    <?php $photographe = get_field('photographe'); echo $photographe; ?> ">
                                 
                                        <img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
                                 
        
                                    Photographe : <?php echo $image['photographe']; ?>
    
                                  
                                    <?php echo $image['caption']; ?>
    
                                    <?php //echo $image['title']; 
                                        ?>
    
                                  
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
    
                <?php
                endwhile; // End of the loop.
                ?>
    
  • A field that you add to attachments is not returned in the array.

    to get the field from the image

    
    Photographe : <?php the_field('photographe', $image['ID']); ?>
    
  • Perfect, it’s working !
    Thank you very much

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.