I found this thread:
https://toolset.com/forums/topic/create-wp-gallery-from-multiple-image-field/
and am trying to do the same thing (Create gallery out of a repeating image field), but cannot get it to work.
I have a repeating image field named "Image Gallery" with the slug 'partner-image-gallery'
I placed this in functions.php
add_shortcode( 'gallery_from_image_fields', function( $atts ){
global $wpdb;
$postid = $atts['postid'];
$slug = 'wpcf-partner-image-gallery' . $atts['slug'];
// Retrieve image field urls
$images = (array) get_post_meta( $postid, $slug, false);
$ids = array();
// Convert the urls to post ids for the images
foreach ($images as $image) {
$attachment = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image ) );
$ids[] = $attachment[0];
}
$ids_list = join( ',', $ids );
$gallery = '[gallery ids="' . $ids_list . '"]';
$out = do_shortcode( $gallery );
return $out;
});
and then this in my page template
[gallery_from_image_fields postid='[wpv-post-id]' slug='partner-image-gallery']
But I can't get it to work. Any idea what I may be doing wrong?
Thanks so much!!
Dear staceyz,
I assume the custom image filed "partner-image-gallery" is created with Types plugin, Types will pre-pend "wpcf-" before the field slug, please try this, edit this line from:
$slug = 'wpcf-partner-image-gallery' . $atts['slug'];
To:
$slug = 'wpcf-' . $atts['slug'];
And test again
Oh - perfect. Thanks for the help and quick reply!