I am following the instructions set out in the ACF Gallery page at https://www.advancedcustomfields.com/resources/gallery/ in how to create a native Wordpress gallery using the shortcode and dynamically populating the item IDs from the data in the ACF Gallery field.
Example:
EDIT: I have slightly modified the code to include definition for $image_ids
<?php
// Load value (array of ids).
$images = get_field('product_images');
$image_ids = get_field('product_images', false, false);
if( $images ) {
// Generate string of ids ("123,456,789").
$images_string = implode( ',', $image_ids );
// Generate and do shortcode.
$shortcode = sprintf( '', $images_string );
echo do_shortcode( $shortcode );
}
Now my problem is that the an error returns saying that the value for $image_ids is undefined, and rightly so, can't see where that gets defined at all.
I've got some older code that I used to use:
<?php
// different product sizes (gallery)
if(get_field('product_images')) : ?>
<h3>Product Images</h3>
<?php
$image_ids = get_field('product_images', false, false);
$shortcode = '[' . 'gallery ids="' . implode(',', $image_ids) . '"]';
echo do_shortcode( $shortcode );
endif;
?>
This code does work but returns an error php notice array to string conversion in jetpack-carousel. Yes I am using the 'Tiled Galleries Carousel Without Jetpack' plugin.
I really want to follow the recommended way set out in the ACF documentation but it does not work for me. What am I doing wrong?
$image_ids = get_field('product_images', false, false);now. Error has gone but not displaying any image gallery. - Ryan Coolwebs