Support

Account

Home Forums Front-end Issues Displaying an ACF image field for a Tag taxonomy within a loop of posts Reply To: Displaying an ACF image field for a Tag taxonomy within a loop of posts

  • Hey John, hopefully you can help me. I am working with ACF Theme Code Pro and the provided code I think works only on an archive page (?). I am just trying to output an image field put on my taxonomy in a WP_Query. Is the below code should be working considering that I need to replace “NULL” with something else? Thanks a lot!

    <?php 
    					
    // Acf Taxonomy Fields
    $taxonomy_prefix = 'category';
    $term_id = NULL;
    $term_id_prefixed = $taxonomy_prefix .'_'. $term_id;
    $image = get_field( 'logo_image', $term_id_prefixed );
    
    // 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 if ( $image ) : ?>
              <img src="<?php echo esc_url( $image['url'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>" class="c-card-article__cat">
            <?php endif; ?>
        
            <?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(); ?>