I have created a Gallery using WordPress on the editor, now I' am trying to get the images url and the caption of the image. From the function follow I' am only able to get the URL and ID's but now the caption.
<?php
$gallery = get_post_gallery( get_the_ID(), false );
var_dump( $gallery );
?>
This is how the var_dump results show
array(2) {
["ids"]=>
string(19) "199,198,197,195,196"
["src"]=>
array(5) {
[0]=>
string(83) "http://example.com/wp-content/uploads/2014/04/fff-10-150x150.png"
[1]=>
string(82) "http://example.com/wp-content/uploads/2014/04/fff-9-150x150.png"
[2]=>
string(82) "http://example.com/wp-content/uploads/2014/04/fff-8-150x150.png"
[3]=>
string(82) "http://example.com/wp-content/uploads/2014/04/fff-6-150x150.png"
[4]=>
string(82) "http://example.com/wp-content/uploads/2014/04/fff-7-150x150.png"
}
}
Is there anything else I have to in place to get the caption of the image?
<?php
$gallery = get_post_gallery( get_the_ID(), false );
$new1 = $gallery['ids'];
$str = $new1;
$str1 = explode(",",$str);
$i = 0;
foreach( $gallery['src'] AS $src )
{
$str2 = wp_get_attachment($str1[$i]);
$caption = $str2['caption'];
?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" /><div><?php echo $caption; ?></div>
<?php
$i++;
} ?>
I think this will help you.