Support

Account

Home Forums Front-end Issues Display taxonomy image in WP_Query Reply To: Display taxonomy image in WP_Query

  • Finally solved, here’s the final code for anyone interested. Will sleep less dumb tonight! Thank you very much John!

    <?php 
    
    // args
    $args = array(
      'order'       => 'DESC',
      'orderby'     => 'date',
      'posts_per_page'	=> -1,
      'post_type'		=> 'post',
    );
    
    // query
    $posts_query = new WP_Query( $args );
    
    ?>
    <?php if( $posts_query->have_posts() ): ?>
      <?php while ( $posts_query->have_posts() ) : $posts_query->the_post(); ?>
      
      <div class="swiper-slide">
        <a href="<?php the_permalink(); ?>" class="c-card-article">
          <div class="c-card-article__img mb-15">
            <div class="c-card-article__overlay">
              <i class="icon-arrow-right"></i>
              <div><?php _e('Plus de d├ętails', 'credo'); ?></div>
            </div>
    
            <?php $terms = wp_get_post_terms($post->ID, 'category');  foreach ($terms as $term) : $image = get_field('logo_image', $term); ?>
              <img src="<?php echo esc_url( $image['url'] ); ?>" class="c-card-article__cat" />
            <?php endforeach; ?>
        
            <?php the_post_thumbnail( 'large', array( 'class' => 'u-w-100' ) ); ?>
          </div>
          <p><?php the_title(); ?></p>
        </a>
      </div>		
    
      <?php endwhile; ?>
    <?php endif; ?>
    
    <?php wp_reset_postdata(); ?>