Home › Forums › ACF PRO › Image field returns a string instead of an array › Reply To: Image field returns a string instead of an array
My search page code is :
<div class="row"> <?php $loop = new WP_Query( array( 'post_type' => 'events','posts_per_page' => -1, 'order=ASC' ) ); if ($loop->have_posts() ): while ( $loop->have_posts() ) : $loop->the_post(); get_template_part( 'loop'); endwhile; else : get_template_part( 'loop', 'empty' ); endif;?> </div>
loop.php content code is (for example) :
<article id="post-<?php the_ID(); ?>"> <div class="card"> <div class="card-image"> <?php $image = get_field('event_cover'); if( !empty($image) ): ?> <img src="<?php echo $image['sizes']['medium'] ?>"/> <?php endif; ?> </div> </div> </article>
This exact same snippet works for displaying the image of all posts in all pages…but not on search page 🙁
And 302 is the good ID (I mean, the ID of the image that should be displayed…).
Thanks for your time and help John 😉
EDIT: some more details that may help.
1) I have a taxonomy field named “event_style”. When I filter posts by this custom field it works great (The image is displayed correctly). It fails only when I use the distance filter to modify the query…
2) I have another image field displayed (as an object) in the header (so it’s outside the loop). This one doesn’t work neither when posts are filtered by distance. Works well on other pages.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.