Home › Forums › Front-end Issues › How to display image field in a loop? › Reply To: How to display image field in a loop?
<?php $args = array( 'post_type' => 'speakers', 'posts_per_page' => 10 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<div class="entry-content">'; echo '<h2 class="speaker-name">'; the_title(); echo '</h2>'; $attachment_id = get_field('field_name'); $size = "thumbnail"; // (thumbnail, medium, large, full or custom size) $image = wp_get_attachment_image_src( $attachment_id, $size ); echo '<img src="' . $image . '" />'; echo '<span class="speaker-title">'; the_field('title'); echo ' / '; the_field('company_name'); echo '</p>'; the_content(); echo '</div>'; endwhile; ?>
Straight from the image field docs. Please read the docs
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!
🗓️ Just one more day until the next session of ACF Chat Fridays! Make sure to register for the latest updates on what’s coming in ACF 6.1!— Advanced Custom Fields (@wp_acf) March 30, 2023
📆 Friday 31st March 3pm UTC
👉 Register here - https://t.co/3UtvQbDwNm pic.twitter.com/7xtEJakeQN
© 2023 Advanced Custom Fields.