Support

Account

Home Forums General Issues Loop ALL fields within sidebar Reply To: Loop ALL fields within sidebar

  • Hi John,

    You’re a genius. Thank you. It’s working perfectly.

    Below is my final code for anyone else needing this fix. Note: I’ve added a hyperlink around the logo to the relevant post.

    <?php $args = array(
      				'post_type' => 'post', // or your post type
      				'posts_per_page' => -1, // get them all
      				'meta_query' => array(
        				array(
          				'key' => 'logo',
          				'value' => '',
          				'compare' => '!='
        				) ) );
    				$query = new WP_Query($args);
    				if ($query->have_posts()) {
    				global $post;
    				while ($query->have_posts()) {
    				$query->the_post();
    					echo '<a href="' . get_permalink() . '">';
    					echo '<img src="' . get_field('logo') . '" /></a>';
      				}
      				wp_reset_postdata();
    				}
    				?>