<?php $loop = new WP_Query( array( 'post_type' => 'gallery', 
        'posts_per_page' => 100 ) 
            ); 
        while ( $loop->have_posts() ) : $loop->the_post(); ?>




    <?php if ( get_post_gallery() ) :


            /* Loop through all the image and output them one by one */
            foreach( $gallery['src'] as $src ) : ?>

                <img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
                <?php
            endforeach;
        endif;

 endwhile; wp_reset_query(); ?>

The above code pulls a WordPress gallery from a custom post named “gallery.” Then it stores and displays the image. Is there a way to also store the caption of the gallery into a variable?

Read more here: Get Image Caption from WordPress Gallery Images


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: