Tell us what you are trying to do?
Make a Gallery of images from a Post Type
Is there any documentation that you are following?
<h3 style="text-align: center;"><span style="text-decoration: underline;">Performer Photo Gallery:</span></h3>
<p>[gallery ids="[wpv-for-each field="wpcf-promo-image-gallery"] {!{types field='promo-image-gallery' title='%%TITLE%%' alt='%%ALT%%' size='medium' resize='proportional' separator=', ' item='$parent'}!}{!{/types}!}[/wpv-for-each]"]</p>
https://toolset.com/2017/10/adding-a-gallery-of-images-for-custom-posts/
Is there a similar example that we can see?
What is the link to your site?
hidden link
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Marcel,
Thank you for contacting our support forum.
I dont see how your setup will work since you are using a repeatable image field . I suspect that the gallery shortcode needs the ID of the post.
What you can do is to try this solution below
https://toolset.com/forums/topic/get-the-image-id-of-the-repeatable-image-fields/#post-1201811
So you will pass this shortcode into the gallery shortcode to pass the ids.
If this does not work please let me know.
Thanks,
Shane
I added the code to my functions.php
I then tried to use the code like this:
<h3 style="text-align: center;"><span style="text-decoration: underline;">Performer Photo Gallery:</span></h3>
[gallery size="medium" ids="[get_image_id id='[wpv-post-id]' field='wpcf-promo-image-gallery']"]
This does not work.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Marcel,
This is the default gallery shortcode for wordpress correct?
Try this new shortcode.
// Add Shortcode
function get_image_id( $atts ) {
global $wpdb;
// Attributes
$atts = shortcode_atts(
array(
'field' => '',
'id' => ''
),
$atts
);
$image_urls = get_post_meta($atts['id'],$atts['field']);
$id_list = array();
foreach ($image_urls as $image_url) {
if(!empty($image_url)){
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
array_push($id_list, $attachment[0]);
}
}
$final_list = implode(",", $id_list);
$out = do_shortcode('[gallery size="medium" ids="'.$final_list.'"] ');
return $out;
}
add_shortcode( 'get_image_id', 'get_image_id' );
This should hopefully resolve the issue. I told it to just output the gallery shortcode.
Please let me know if this helps.
Thanks,
Shane
Okay, let me see if I can work out how to use this shortcode:
- It must always show a Gallery based on the current Post ID
I've modified the shortcode output to this:
$out = do_shortcode('[TS_VCSC_Lightbox_Gallery content_images_altdata="false" content_style="Freewall" fullwidth="true" breakouts="4" lightbox_effect="fade" lightbox_backlight="hideit" lightbox_save="true" ids="'.$final_list.'"][/TS_VCSC_Lightbox_Gallery] ');
What is the usage of this shortcode? Is it [get_image_id id="[wpv-post-id]" field="wpcf-promo-image-gallery"]?
If I use the above shortcode, this is the output: -> " field="wpcf-promo-image-gallery"]
As I understand, .$final_list needs to be list of IDs of images attached to the Post ID (the current Profile)
Here's what the shortcode SHOULD have:
$image_urls = get_post_meta(get_the_ID(),$atts['field']);
Herewith the final working code:
// Add Shortcode
function get_perf_gallery( $atts ) {
global $wpdb;
// Attributes
$atts = shortcode_atts(
array(
'field' => '',
'id' => ''
),
$atts
);
$image_urls = get_post_meta(get_the_ID(),$atts['field']);
$id_list = array();
foreach ($image_urls as $image_url) {
if(!empty($image_url)){
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
array_push($id_list, $attachment[0]);
}
}
$final_list = implode(",", $id_list);
$out = do_shortcode('[TS_VCSC_Lightbox_Gallery content_images_altdata="false" content_style="Freewall" fullwidth="true" breakouts="4" lightbox_effect="fade" lightbox_backlight="hideit" lightbox_save="true" content_images="'.$final_list.'"][/TS_VCSC_Lightbox_Gallery] ');
return $out;
}
add_shortcode( 'get_perf_gallery', 'get_perf_gallery' );