Had the same query and stumbled on this page.
I found a solution that works perfectly for anyone else that ends up here.
1. Create a new ACF Field Group e.g. “Media Metadata”
2. Add a field as a Link or Page Link or URL (I used Page Link)
3. Then under Location => Rules “show this field group if” = Attachment
4. This will add a new link field into each media library item
I used a Page Link and added links to my Media in the Media Library.
So when calling it in my Gallery loop code:
<?php foreach( $images as $image ): $link_id = get_post_meta( $image['id'], 'page_link', true); ?> <a href="<?php the_permalink( $link_id ); ?>" title="<?php echo $image['alt']; ?>"> <img data-src="<?php echo $image['sizes'][$size]; ?>"/></a> <?php endforeach; ?>
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!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.— Advanced Custom Fields (@wp_acf) January 6, 2023
© 2023 Advanced Custom Fields.