I created a “books” custom taxonomy for my “book” CPT. Using ACF, I assigned an image to each my custom taxonomy terms.
I have a page where I display all my “books” terms as images. It works but now I want to specify a particular size to these images. The code of the page:
<?php
$taxonomy = 'books';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_terms) {
$taxonomy_image = get_field( 'taxonomy_image', 'books_'.$tax_terms->term_id );
$taxonomy_image_url = $taxonomy_image['url'];
?>
<img src="<?php echo $taxonomy_image_url; ?>" alt="" />
<?php
}
?>
</ul>
I think the ACF doc page about images contains the key to what I’m trying to do – especially the part about image size, but I can’t seem to find a way to integrate it to my code successfully. Any suggestion?
It appears you currently have the field set to return the image object, if you scroll down to the bottom of the page you linked you’ll see an example object:
so for a specific size you want to replace
$taxonomy_image['url']
with$taxonomy_image['sizes']['thumbnail']
, wherethumbnail
is the desired size key.