Soliloquy Dynamic Slider for Current Post and Exclude an ACF Image ID

It’s not as though it was “really” a problem. But that I couldn’t figure it out caused me to lose sleep. I hate that shit.

So what was going on?
I am using Soliloquy along with the Dynamic Addon to automagically create sliders from attached images to the current post.

function digisavvy_dynamic_slider() {
	global $post;
	$dg_post_id = $post->ID;
	if ( function_exists( 'soliloquy_dynamic' ) ) soliloquy_dynamic( array( 'id' => "$dg_post_id" ) );

This snippet grabs the current post ID and stores it in the $dg_post_id variable. Nice.

The problem:
This pulled all the attached images for the current post, as expected. What I didn’t expect was that it pulled an image from an ACF (Advanced Custom Fields) image field I’d set up. Not cool. So I needed to exclude that image from getting pulled into the slider.

function digisavvy_dynamic_slider() {
	global $post;
	$imageArray = get_field('project_cover_image'); // Array returned by Advanced Custom Fields
 	$imageID = $imageArray['id']; // Grab the field's 'ID' from the array
	$dg_post_id = $post->ID; // Grab the current post's 'ID'
	if ( function_exists( 'soliloquy_dynamic' ) ) soliloquy_dynamic( array( 'id' => "$dg_post_id", 'exclude' => "$imageID" ) );

Same code as the previous snippet, except now we’re grabbing data out of the ACF field’s array. First, the field had to be set to ‘Image Object’ as it stores all the gooey meta-data we need.

Next we set the field and store it to the $imageArray variable. And, then, using setting the $imageID variable, we simply pull the ‘ID’ from the image object array and then set the variable inside Soliloquy function for the exclude parameter.

Special props:

Leave a Reply