I am trying to get the text stored in an image caption on WordPress. I have code that gets the images attached to a post and with a second bit of code I can display them later in the page.
This is what gets the images attached to the post.
<?php
if ($attachments = get_children(array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
)));
foreach ($attachments as $attachment) {
$mynewarray = wp_get_attachment_image_src($attachment->ID, 'full');
$anotherarray [] = $mynewarray[0];
} ?>
And this displays each image, I just change the [2] to call different images.
<?php echo $anotherarray[2]; ?>
All works well, but i want to get the text stored in the caption, I started this a few months ago and spend days trying to get the caption, gave up and just coming back to this now. So lost as, any help appreciated.
Thanks for the suggestions, but nothing has worked yet, I think this its coz I am calling all images attached to a post as an array. And then using the array parts to set the images as a background to a div.The method in the post listed as a smiler question does not work in this case.