Support

Account

Home Forums Add-ons Repeater Field Images in Repeater not working

Solved

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!

  • Just run that, and I’m getting “Null” as the var_dump output.

  • 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!

  • 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!

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

The topic ‘Images in Repeater not working’ is closed to new replies.