Skip to content

Instantly share code, notes, and snippets.

@ericakfranz
Created December 4, 2015 18:07
Show Gist options
  • Save ericakfranz/48e1d15856de40cd2b5b to your computer and use it in GitHub Desktop.
Save ericakfranz/48e1d15856de40cd2b5b to your computer and use it in GitHub Desktop.
Get the IDs of all images attached to a post via ACF gallery field, and output to an Envira Gallery using the Dynamic Addon
<?php
$gallery = get_post_meta( get_the_ID(), 'gallery_images' ); // 'gallery_images' is name of the ACF gallery field
$post_id = get_the_ID(); // grab the ID of the post to build into our Dynamic gallery's custom ID
// If we have something output the gallery
if( isset( $gallery[0] ) && is_array( $gallery[0] )) {
$image_ids = $gallery[0];
envira_dynamic( array(
'id' => 'post-gallery-' . $post_id . '',
'images'=> implode( ',', $image_ids ),
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment