Home › Forums › ACF PRO › Get gallery from post object › Reply To: Get gallery from post object
Hi @James
Thank you so much – I’m calling this from functions.php so it’s outside the loop. I only need one gallery so didn’t need the foreach
wrapped round the $post_objects
variable (and so changed $post_object->ID
to $post_objects->ID
for the ‘gallery’ field.
function show_page_gallery() {
global $post;
$post_objects = get_field('gallery_select',$post->ID);
if( $post_objects ):
$images = get_field('gallery',$post_objects->ID);
if( $images ):
foreach( $images as $image ):
echo '<img src="'.$image['url'].'" />';
endforeach;
endif;
endif;
}
The example above is much simplified but works. I’ve now added back all the HTML required to wrap and style the gallery images and it’s displaying perfectly.
Thanks again.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.