简体   繁体   English

Wordpress获得附件图片标题

[英]Wordpress get attachment image caption

I tried to get attachment meta caption value as mentioned here , but couldn`t get any output. 我试图获得附件元标题值,如此处所述 ,但无法获得任何输出。 Other meta arrays like [created_timestamp] or [iso] gave their values. 其他元数组如[created_timestamp]或[iso]给出了它们的值。

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

This issue happens to both [caption] and [title]. [caption]和[title]都会出现此问题。 Any help is much appreciated. 任何帮助深表感谢。

The caption and title you are looking to get from wp_get_attachment_metadata are not the title and caption you add in WordPress they are meta data from the actual image itself. 您希望从wp_get_attachment_metadata获取的标题和标题不是您在WordPress中添加的标题和标题,它们是来自实际图像本身的元数据。 To get the WordPress data use something like this (assuming $id is the id of your image). 要获取WordPress数据,请使用以下内容(假设$ id是图像的ID)。

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

从WordPress 4.6.0开始,有get_the_post_thumbnail_caption($post)可以获取指定帖子的标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM