Support

Account

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.