Home Forums Add-ons Repeater Field Add title from repeater field to image title


Add title from repeater field to image title

  • Hi

    I have a Repeater field called Images that has the sub fields ‘image’ and ‘title’

    I’m creating a li list with the images. I would like to add the image title from the title sub field to the image. How do I add the title sub field.

    		<section class="gallery">
    			$rows = get_field('images');
    				echo '<ul>';
    				foreach($rows as $row){
    					$attachment_id = $row['image'];
    					$thumb = "thumbnail";
    					$large = "large";
    					$thumb_img = wp_get_attachment_image_src( $attachment_id, $thumb );
    					$large_img = wp_get_attachment_image_src( $attachment_id, $large );
    					echo '
    						<a href="'.$large_img[0].'">
    							<img class="alignnone size-full wp-image-100 img" src="'.$thumb_img[0].'" alt="img" width="'.$thumb_img[1].'"	height="'.$thumb_img[2].'" title="'.the_sub_field('title').'"/>
    				echo '</ul>';
  • Hi @ttmt_101

    Because you are using abasic PHP aproach to looping through your repeater rows, you need to use the code $row['title'] to load the relative title value. Using the_sub_field will not work in this situation.


Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Add title from repeater field to image title’ is closed to new replies.