'Taxonomy Custom field image is not showing
I want to show taxonomy custom field images on loop on the home page "developers" is taxonomy name and "developer_logo" is image field slug I used that code only name is showing but image is not showing
<?php
$terms = get_terms( array( 'taxonomy' => 'developers', 'hide_empty' => false ) );
$image = get_field('developer_logo');
foreach ( $terms as $term ) : ?>
<div class="col-lg-4 col-md-6">
<div class="product product-zoom product--card">
<div class="product__thumbnail">
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo $term->name; ?>">
</div>
<div class="product-desc">
<h4 class="text-center mb-2"><?php echo $term->name; ?></h4>
</div>
</div>
</div>
<?php
endforeach
?>



I just want to show the images of taxonomy custom field
Solution 1:[1]
**In the below code, i have added the term Id as second parameter in get_field() function to get image URL & replaced the $image variable from outside of loop to inside the foreach loop.**
<?php
$terms = get_terms(array(
'taxonomy' => 'developers',
'hide_empty' => false
));
foreach ($terms as $term) {
$image = get_field('developer_logo', $term->id); ?>
<div class="col-lg-4 col-md-6">
<div class="product product-zoom product--card">
<div class="product__thumbnail">
<img src="<?php echo $image; ?>" alt="<?php echo $term->name;?>">
</div>
<div class="product-desc">
<h4 class="text-center mb-2"><?php echo $term->name;?></h4>
</div>
</div>
</div>
<?php
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
