Is it possible to get the description/caption or other meta information of the featured image used in a post?
Hi Regnalf,
Thanks for reaching out.
The featured image attachment id is stored in the post_meta table, with the meta_key named _thumbnail_id. Use that post id to find the post meta with meta_key named _wp_attachment_metadata. The value of that is a serialized array with keys thumb, file, width, height, sizes (an array), and image_meta (an array).
The file value is relative to the uploads directory for the WP install, and points to the original full-sized image. You should be able to calculate the URL from that. Sizes have an image size as their key (e.g., ‘small’, ‘medium’, ‘large’, ‘thumbnail’), and the value is an array with keys file, height, and width. The image_meta will contain things like exif/iptc image metadata from the image itself.
If you are not proficient with the coding and WordPress structure, I would suggest you hire a developer who can assist you to do the customization or you can avail of our newly launched service called One, where the customization questions are answered.
Hope it helps.
Not quite what I was looking for. I actually meant the metadata you enter yourself in the WordPress media library.
I just wanted to know if this already comes from the metadata query from your system.
So if want to get the caption of the media in the wordpress library the function
{{dc:post:meta key="_thumbnail_id"}}
does give me the correct ID (e.g. 20), and I can then read the excerpt (in that case the caption) from the post table (not postmeta) with
{{dc:post:excerpt post="20"}}
But I can’t do this dynamically by connecting both functions. For example like this:
{{dc:post:excerpt post="{{dc:post:meta key="_thumbnail_id"}}"}}
Would be nice feature if you could nest such things though.
Anyway, for all of you who have the same problem, I currently solved it with a custom shortcode in the function.php [post-thumbnail-caption]:
add_shortcode('post-thumbnail-caption', 'sc_thumbnail_caption');
function sc_thumbnail_caption ($post)
{
return get_the_post_thumbnail_caption($post);
}
I hope more of this functionality is comming in the next updates.
Cheers
Hi @Regnalf,
We’re glad that you’re able to find a solution to your issue. On the other hand, I will make a feature request so it might be taken into account in the future.
Thank you.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.