admin管理员组

文章数量:1323224

I'm trying to find all the meta fields that are used for an attachment: like Title, alternative text, description and caption . I've looked all over and the only one I was able to find was for an Alternative text, which is _wp_attachment_image_alt.

I'm trying to find all the meta fields that are used for an attachment: like Title, alternative text, description and caption . I've looked all over and the only one I was able to find was for an Alternative text, which is _wp_attachment_image_alt.

Share Improve this question asked Oct 13, 2020 at 2:27 Gregory SchultzGregory Schultz 6236 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can easily inspect all the metadata for any post like so:

// 123 is the (attachment) post ID
var_dump( get_post_meta( 123 ) );

And in a default WordPress setup with no plugins or theme which add custom metadata to the image attachment post, the metadata you'd get are:

  • _wp_attached_file — string, the image file (path and name) for the attachment post

  • _wp_attachment_metadata — array (serialized), the sizes for the image like 'thumbnail' (including original size), and metadata from EXIF/IPTC info.

  • _wp_attachment_image_alt — string, the image's alternative text

As for the other details like the image title, they are in the post data (in the posts database table), so you can for example use wp_update_post() to update these details:

  • post_title — image title

  • post_excerpt — image caption

  • post_content — image description

本文标签: functionsWhat are the meta fields for an attachment