Alfred Kwak Alfred Kwak - 1 year ago 192
PHP Question

ACF Repeater in Wordpress not showing images

I'm having trouble getting images shown with a repeater in Wordpress.
For some reason it only shows the alt text instead of the image itself?

the upper images are my thumbnail posts and are showing correctly.
Does anyone know whats causing this?

my code

<div class="row">
<div class="col-sm-6 left"><h1>COMMERCIAL</h1><br>
<div class="page-header">

<?php $mymovies = new WP_Query(array(
'post_type' => 'my_movies'
)); ?>

<?php while($mymovies->have_posts()) : $mymovies->the_post(); ?>
<div class="movie-colums">
<div class="thumbtitle group">
<div class="preview">
<?php the_post_thumbnail('thumbnail'); ?>
<h1><?php the_title(); ?><br>
<?php the_field('year'); ?>
// check if the repeater field has rows of data
if( have_rows('images_rep') ):
// loop through the rows of data
while ( have_rows('images_rep') ) : the_row();
// display a sub field value
else :
// no rows found

<?php endwhile; ?>

thanks in advance

Answer Source

Your PHP bit for the repeater stuff should be:

<?php if( have_rows('images_rep') ): ?>

    <?php while( have_rows('images_rep') ): the_row(); 
        $image = get_sub_field('image');

        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>">

    <?php endwhile; ?>

<?php endif; ?>

It looks like your example is outputting the image object so just wrap the image URL in an image tag.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download