ericakfranz
12/4/2015 - 6:07 PM

Get the IDs of all images attached to a post via ACF gallery field, and output to an Envira Gallery using the Dynamic Addon

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 ),
  ) );
}