Get image from taxonomy term using ACF Get image from taxonomy term using ACF wordpress wordpress

Get image from taxonomy term using ACF


Ok, so you are getting the value of the field, you just need to set how it should output, like so:

$image = get_field('image', $taxonomy . '_' . $term_id);echo '<img src="'.$image['sizes']['thumbnail'].'" alt="$image['alt']" />';

This assumes that you want to use the thumbnail image size. If using a different size, change that text to the appropriate image size.

If you want to return the full size image, use the following code:

$image = get_field('image', $taxonomy . '_' . $term_id);echo '<img src="'.$image['url'].'" alt="$image['alt']" />';


  <?php                                 $terms = get_field('best_seller_laptops_pc_category');                                if( $terms ): ?>                                <?php foreach( $terms as $term ):                                    $thumb_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );                                    $term_img = wp_get_attachment_url(  $thumb_id );                                ?>           <div class="col-lg-6">                <div class="addbox1">                    <img alt="" src="<?php echo $term_img;?>">                    <div class="contain">                        <h3>                           <?php echo esc_html( $term->name ); ?>                        </h3>                        <h4><?php echo esc_html( $term->description ); ?></h4>                        <a href="<?php echo get_term_link( $term ); ?>">LEARN MORE</a>                        <a href="<?php echo get_term_link( $term ); ?>" class="btn">buy now</a>                    </div>                </div>            </div>        <?php endforeach; ?>        <?php endif; ?> 


taxonomy.php is a template for a custom taxonomy based on the same model of archives.phpIn this kind of template, you should use the wordpress loop

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Them, you can pass in get_field, the post ID like that as 2nd parameter:

$image = get_field('image', $post->ID);