Wordpress gets attached image caption

I tried to get the metafile binding value as mentioned here , but could not get any result. Other meta arrays, such as [created_timestamp] or [iso], have given their values.

$img_meta = wp_get_attachment_metadata( $id ); echo $img_meta[image_meta][caption]; 

This issue occurs with both [caption] and [title]. Any help is greatly appreciated.

+5
source share
2 answers

The title and title you want to get from wp_get_attachment_metadata are not the title and the title you are adding to WordPress, they are metadata from the actual image itself. To get WordPress data, use something like this (assuming $ id is the identifier of your image).

 $image = get_post($id); $image_title = $image->post_title; $image_caption = $image->post_excerpt; 
+9
source

Since WordPress 4.6.0 there is get_the_post_thumbnail_caption($post) that gets the header for the specified post.

+5
source

Source: https://habr.com/ru/post/1240099/


All Articles