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">
    $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');
    			else :
    				get_template_part( 'loop', 'empty' );

    and loop.php content code is (for example) :

    <article id="post-<?php the_ID(); ?>">
      <div class="card">
        <div class="card-image">
            $image = get_field('event_cover');
            if( !empty($image) ): ?>
            <img src="<?php echo $image['sizes']['medium'] ?>"/>
            <?php endif; ?>

    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.