Home › Forums › ACF PRO › Image field returns a string instead of an array › Reply To: Image field returns a string instead of an array
hi John, thanks for answering.
I have a template part named ‘loop.php’, which I use to display all loops in my application.
In this file I use the following code to display image from custom field:
<?php $image = get_field('event_cover'); if( !empty($image) ): ?> <img src="<?php echo $image['sizes']['medium'] ?>" alt="<?php echo $image['alt']; ?>" /> <?php endif; ?>
$image gets an array of values (as expected) in all pages, but not in search results page if posts are filtered by distance… it gets a string value instead.
Not sure if I’m clear… sorry
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.