WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In regards to my previous question about shortcode captions, it doesn't appear to me that the actual text of a caption is stored anywhere other than in the post content within the shortcode itself.

I would have thought that wp_get_attachment_metadata would store the info for an attachment, but it doesn't.

Am I wrong? Or does WordPress not store the actual caption anywhere?

share|improve this question
wp_get_attachment_metadata stores the file data. If a JPEG had EXIF data, that would've got stored there too. The posts table stores the attachment data (so things like the title, caption, author, date etc.). Nothing retarded about that in my books ;) – TheDeadMedic Jun 20 '11 at 18:16
up vote 2 down vote accepted

Yes, it stores the caption in it's own place in the DB. I can't quote the exact location but in Wordpress, "Attachments" are a post type and it stores each attachment just like a post. For an attachment post type, it treats the Image Caption as the_excerpt the Image Description as the_content and the Image Title as... the_title.

share|improve this answer
You're right. That's a totally retarded way of doing it, but you're right. It's stored in the wp_posts table with post_type=attachment – Dan Gayle Sep 14 '10 at 16:47

where $post_id is the current post, this code will output all the attachments of a post, and their titles descriptions and captions

$q = new WP_Query( array(
    'post_parent' => $post_id,
    'post_type' => 'attachment'
        <h3><?php the_title(); ?></h3>

        if ( wp_attachment_is_image( $post->id ) ) {
            $att_image = wp_get_attachment_image_src( $post->id, "large");
<img src="<?php echo $att_image[0];?>" width="<?php echo $att_image[1];?>" height="<?php echo $att_image[2];?>"  class="attachment-large" alt="<?php $post->post_excerpt; ?>" />

        // caption

        // description

Attachments are all children of the post they are attached to, and you can use this to do your own custom gallery code. They also have a lot of data in their custom fields, such as image dimensions, EXIF data, etc They can even be commented on.

You can take the code from the inner loop and place it in attachment.php in your theme, just double check I haven't made any syntax typos before you do.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.