On my page the gallery images are cycled and I would like to show their title as a caption. Since get_post_gallery_images
only retrieves the thumbnail-url of the gallery images I have tried to use get_attached_media('image', $post);
instead.
The following code gives me the url and the title of the gallery images:
foreach($images as $image) {
$titleArr[] = $image->post_title;
$urlArr[] = wp_get_attachment_url($image->ID);
}
However, get_attached_media('image', $post);
returns all images that have ever been attached to this post, even if they are no longer used in the post. Also, for posts where the gallery images are attached to another post, they do not appear.
Is there an equivalent of get_attached_media('image', $post);
that returns all the image urls and titles of the images currently in the gallery. Preferably in gallery order.