Get ACF Custom Field Category / Taxonomy Term Image in Loop

I use this fairly often. I find working with plugins I already have installed is better than installing additional plugins to resolve the issue I’m trying to accomplish more reliable.

<ul class="blog_icons">
	$categories = get_the_terms( get_the_ID(), 'category' );

	foreach( $categories as $category ) {
		// echo $category->term_id . ', ' . $category->slug . ', ' . $category->name . '<br />';
		$image = get_field('icon', $category) ?>
			<li><a href="<?php bloginfo('url'); ?>/category/<?php echo $category->slug; ?>"><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a></li>
	<?php } ?>


Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.