Closed cdwharton closed 10 years ago
@weare2ndfloor if you are wanting it output in the image tag, you can use the filter noted in http://wordpress.org/support/topic/caption-3
Otherwise, if you need it separately, something like this should work (assuming you are in a loop of the post w/the thumbnails):
$thumb_post_id = get_post_thumbnail_id('post', 'secondary-thumbnail', get_the_ID());
$thumb_post = get_post($thumb_post_id);
$caption = trim(strip_tags( $thumb_post->post_excerpt ));
Obviously, you'd want some error handling around getting the thumbnail ID and thumbnail post.
Hi Chris, this doesn't seem to work :(
I found a solution to get "alt", "caption", "description" and "title"using 2 functions from this post:
function get_attachment_id_from_src ($image_src) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
$id = $wpdb->get_var($query);
return $id;
}
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
Get URL of your image first, then attachment ID and then what you want:
$imgPath = MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-thumbnail');
$imgIdAttachment = get_attachment_id_from_src( $imgPath );
$metaImgDescription = $metaImg['description'];
This can be more simply/cleanly/best-practicingly done w/the code noted on this support thread.
Mea culpa : finally the chrisscott solution work for me
Hi, I love this plugin and use it all the time :)
I do have an issue though, I can't seem to retrieve the image caption - I've found this online but it doesn't seem to work. I'm sure there is a simple solution though. If there is it would be good if you could update your docs with it too :)