Support

Account

Home Forums Add-ons Repeater Field Image alt text in Repeater fields

Solving

Image alt text in Repeater fields

  • Hi Everyone,

    I’m having trouble retrieving the alt text from slideshow images in an ACF Repeater field using a foreach loop. $image[‘alt’] is not working because of this foreach loop. The repeater field is called ‘slideshow’ and the sub field is called ‘foto’. The code I’m using now gives me the alt text from the featured image in WordPress, which is a thumbnail image, but I like to get the alt text from the slideshow images itself. I just can’t get it to work.

    Here’s my code:

    
    <div class="row">
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<div class="col-md-8">
    		<div class="main-content">
    
    			<?php $the_query = new WP_Query('post_type=projecten&posts_per_page=-1'); ?>
    
    			<!-- SLIDESHOW BOOTSTRAP CAROUSEL -->
    			<div id="carousel-projecten" class="carousel slide" data-ride="carousel" data-interval="6000">			        	
    
    			<!-- Wrapper for slides -->
    			<div class="carousel-inner" role="listbox">
    				<?php
    					$slides = get_field('slideshow');
    					$image_id = get_post_thumbnail_id();
    					$image_url = wp_get_attachment_image_src($image_id, 'image-size', true);
    					$image_meta = get_post_meta($image_id, '_wp_attachment_image_alt', true);				
    					if($slides) {
    						$pp = 0;
    						foreach($slides as $s) {
    							if ($pp == 0) { $klasse = 'item active'; }
    							else { $klasse = 'item'; }
    								echo '<div class="'.$klasse.'">';
    								echo '<img src="'.$s['foto'].'" alt="'.$image_meta.'" />';
    								echo '</div>';
    								$pp++;
    					}} 
    				?>
    			</div><!-- end wrapper for slides -->
    
    			<!-- Controls -->
    			<a class="left carousel-control" href="#carousel-projecten" role="button" data-slide="prev">
    				<span class="glyphicon glyphicon-chevron-left"></span>
    				<span class="sr-only">Previous</span>
    			</a>
    			<a class="right carousel-control" href="#carousel-projecten" role="button" data-slide="next">
    				<span class="glyphicon glyphicon-chevron-right"></span>
    				<span class="sr-only">Next</span>
    			</a>
    
    			</div><!-- end carousel-homepage -->
    
    		</div>
    	</div>
    	<?php endwhile; endif; ?>
    </div>
    

    Below a link to the live site
    Link to the live site

  • This reply has been marked as private.
  • Hi James,
    Thanks for your reply. According to the documentation, the example you’re giving is used with ACF Gallery, but is this applicable to ACF Repeater as well? I have an ACF with about ten custom fields and one repeater field (slideshow) with just images (foto), used for the slideshow. The alt text I need is from the images within the repeater field. My clients have to fill in the alt text for every image they upload and the code has to fetch this alt text.
    I think you’re right about the array, but I don’t know how to code this.

    Hans

  • This reply has been marked as private.
  • This reply has been marked as private.
  • Whats the point of marking this as private? It would have been great to see how you resolved this, and I am sure others would benefit to!

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

The topic ‘Image alt text in Repeater fields’ is closed to new replies.