Hi,
In the code below from "Loop Item" in "Templates for this View", I have made a custom field, 'picture-title', because I can't figure out a way to access the Caption metadata from the Media image's attachment data. This is obviously not ideal, as the user will have to populate both Caption and Picture Title with the same information (galleries and light boxes will use Caption, whereas my screen would need Picture Title if I can't resolve this - not ideal!)
I thought I had stumbled on a rather obvious answer where I can insert Post Featured Image a second time, but this time select "Caption of the Image" from the "What to display" drop-down, giving me this short code: [wpv-post-featured-image output="caption"]. However, no output is produced.
I read this and related articles (https://toolset.com/forums/topic/caption-for-repeatable-images-field/), so I think there is a problem in this area. I have tried to follow the workaround, but without success.
So, to summarise, what custom function do I need, and what would I replace [types field='picture-title'][/types] with below so I could actually get rid of that field, and just reference each image's Caption.
CODE
<div class="row">
<div class="col-sm-12">[wpv-post-featured-image size="medium"]</div>
</div>
<div class="row">
<div class="col-sm-12">[types field='picture-title'][/types]</div>
</div>
Thanks very much for your help.
Steve
Hi, I'm not quite sure I understand what type of image you are describing. Are you trying to show the post's featured image and its caption, are you trying to show an image stored in a post's custom field and that image's caption, or are you trying to show multiple images stored in a single repeating custom field and the captions of each of those images? The procedure is different for each of these cases.
Hi Christian,
Thanks for coming back to me.
I am looping through posts of type "Media", and picking up "featured image". I want the Captions from those to display under each one.
I've attached some screen shots which should help.
Many thanks.
Steve
Okay I have this custom shortcode you can use to access a Media post's caption:
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'];
}
Add that code to your child theme's functions.php file. Then in a loop of Media posts, you can use the shortcode like this:
[toolset_get_image_caption url="[wpv-post-url]"]
Thank you Christian. That works perfectly :)!
Best wishes,
Steve
I had exactly the same issue, so thanks from me too, Peter