Problem: I would like to create a slider. Each slide should be an image from a repeating custom field in a single post, along with its caption as stored in the Media Library.
Solution:
This isn't possible using a standard Views slider. This approach requires custom code. Follow the steps outlined in this post:
https://toolset.com/forums/topic/create-a-slider-with-multiple-images-from-image-fields/
To display the image caption, add this custom shortcode function to functions.php:
add_shortcode( 'toolset_get_image_caption', 'toolset_get_image_caption_func'); function toolset_get_image_caption_func($atts) { global $wpdb; $url = $atts['url']; $id = $wpdb->get_var( $wpdb->prepare ("SELECT ID FROM $wpdb->posts WHERE guid=%s ORDER BY `ID` DESC", $url ) ); $excerpt = get_the_excerpt($id); if($excerpt) return $excerpt; $attachment_meta = get_post_meta( $id, '_wp_attachment_metadata', true ); if (isset($attachment_meta['image_meta'])) return $attachment_meta['image_meta']['caption']; }
Then use the shortcode like so:
[toolset_get_image_caption url="[types field='gallery' url='true']"]
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 15 replies, has 2 voices.
Last updated by Junichiro Taira 6 years, 11 months ago.
Assisted by: Christian Cox.