Home › Forums › Add-ons › Repeater Field › Images in Repeater not working
Basically put, this is effectively for my website’s “meet the team” page. All the content links work absolutely fine, just so long as its text based. The images in the else statement work, but as soon as I add an image using the ACF backend on the particular page, I just get the broken image symbol and no image displayed. Not entirely sure why? Any help would be fantastic.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(array('topmargin','row')) ?> id="post-<?php the_ID(); ?>">
<?php if( have_rows('staff') ): ?>
<?php while( have_rows('staff') ): the_row();
$image = get_sub_field('image');
$name = get_sub_field('name');
$link = get_sub_field('link');
$title = get_sub_field('title');
$phone = get_sub_field('phone');
$email = get_sub_field('email');
?>
<div class="col-md-3">
<a class="community" href="<?php echo $link; ?>" style="background-image: url(<?php echo $image['url']; ?>);">
<?php if ($image){ ?>
<img class="img-responsive" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php }else{ ?>
<img class="img-responsive" src="<?php echo get_bloginfo('template_directory');?>/assets/img/profileblank.jpg">
<?php } ?>
<h3><?php echo $name; ?></h3>
<h4><?php echo $title; ?></h4>
<?php if ( is_user_logged_in() ) {?>
<h5>Phone: <?php echo $phone; ?></h5>
<h5>Email: <?php echo $email; ?></h5>
<?php } ;?>
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
Hi @giantkiwi
Could you please var_dump() the $image
variable? This page should give you more idea about it: https://www.advancedcustomfields.com/resources/debug/.
It will show if the image was returned correctly or not.
Thanks!
Hi @giantkiwi
It means there’s something wrong with the saved data. Does the image show up on the backend? Could you please re-save the post/page?
If that doesn’t help, could you please share the JSON or XML export of your field group so I can test it out on my end?
Thanks!
JSON for it – https://gist.github.com/anonymous/5b175819ae28ba5e374dcdce31e19c95
resaving the page didn’t help.
Hi @giantkiwi
Thanks for sharing the JSON export.
It seems that you set the return value to “Image URL” which means that the $image
variable won’t have the “url” and “alt” value.
Could you please try to set the return value to “Image Array” instead? I’ve attached a screenshot for your reference.
Thanks!
The topic ‘Images in Repeater not working’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.