David Rhoden
David Rhoden

Reputation: 952

How do I retrieve metadata from the Wordpress Media Gallery?

In the Wordpress Media Library, when you add a piece of media, you're invited to also add other 'metadata': Title, Caption, Alternate Text, and Description.

Using get_the_title() will return the title, but trying get_the_caption() simply breaks the page.

How do I get this data, or metadata on the page. I've also tried using wp_get_attachment_metadata(), which returns an array. Does anyone know what values are in this array? I know it has height and width.

Upvotes: 0

Views: 425

Answers (1)

Travis Nelson
Travis Nelson

Reputation: 2620

I see that this metadata is stored to the wp_posts table. For example, the caption for a photo is in column post_excerpt. Since the title column is post_title, you might want to try the same naming convention and try a call to get_the_excerpt(). Here are the other names of the columns in the wp_posts table

post_author post_date post_date_gmt post_content post_title post_excerpt post_status comment_status ping_status post_password post_name to_ping pinged post_modified post_modified_gmt post_content_filtered post_parent guid menu_order post_type post_mime_type comment_count

Hope this helps

Upvotes: 1

Related Questions