The issue occurred because you tried to get the field outside The Loop. If you want to get it outside the loop, you need to provide the post ID. This page should give you more idea about it: http://www.advancedcustomfields.com/resources/get_field/.
Please try this code instead:
<?php $loop = new WP_Query( array( 'post_type' => 'sponsor', 'orderby' => 'post_id', 'order' => 'ASC') ); ?> <div id="hero" class="sponsor-row clearfix"> <?php while( $loop->have_posts() ) : $loop->the_post(); $sponsor_image = get_field('sponsor_image'); $sponsor_url = get_field('sponsor_url'); ?> <div> <img src="<?php echo $sponsor_image["url"]; ?>" alt="<?php echo $sponsor_image["alt"]; ?>" /> <a href="<?php echo $sponsor_url; ?>">LOLO</a> </div> <pre> <?php var_dump( $sponsor_image ); ?> </pre> <?php endwhile; ?> </div> <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
I hope this helps.
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!
© 2022 Advanced Custom Fields.