Wordpress 获取附件图片标题 [英] Wordpress get attachment image caption

查看:26
本文介绍了Wordpress 获取附件图片标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将附件元标题值设为 此处提及,但无法获得任何输出.[created_timestamp] 或 [iso] 等其他元数组给出了它们的值.

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.

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

[caption] 和 [title] 都会出现此问题.非常感谢任何帮助.

This issue happens to both [caption] and [title]. Any help is much appreciated.

推荐答案

您希望从 wp_get_attachment_metadata 获得的标题和标题不是您在 WordPress 中添加的标题和标题,它们是来自实际图像本身的元数据.要获取 WordPress 数据,请使用类似的方法(假设 $id 是您图片的 ID).

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. To get the WordPress data use something like this (assuming $id is the id of your image).

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

这篇关于Wordpress 获取附件图片标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆