Support » Plugins and Hacks » How to get image caption

How to get image caption

  • I have a partially working snippet of code but need a small bit of assistance to finish it off! The code below at present just grabs the caption of the first image and applies it to every image in the loop. What I would like to happen is to display each image’s unique caption alongside the image – what’s wrong with my code please?

    <?php if(get_field('post_images')): ?>
    		<?php while(the_repeater_field('post_images')): ?>
    			<?php 	$image = wp_get_attachment_image_src(get_sub_field('post_image'), 'large');
    					$largeImage = wp_get_attachment_image_src(get_sub_field('post_image'), 'full');
    					$attachment_id = get_post_thumbnail_id($post_id); ?>
                <li class="block <?php  the_sub_field('module_class');?> gallery-image">
                <a class="block-inner" href="<?php echo $largeImage[0]; ?>" title="<?php $attachment = get_post($attachment_id); echo($attachment->post_excerpt); ?>">
    	    	<img src="<?php echo $image[0]; ?>" alt="<?php $attachment = get_post($attachment_id); echo($attachment->post_excerpt); ?>" /></a></li>
    	    <?php endwhile; ?>
    		<?php endif; ?>
  • The topic ‘How to get image caption’ is closed to new replies.