Show ACF Custom Image Field on Single / Archive

Displaying an image from an ACF custom field is slightly different on an Archive / Single page, versus on a page, or in a regular loop.

<?php $types = get_terms( array(
    'taxonomy' => 'category',
    'hide_empty' => true,
) );

foreach($types as $type) {
    
    $image = get_field('thumbnail', 'category_' . $type->term_id . '' );
    
    if( in_category($type->term_id )) {
        echo '<img src="' . $image['url'] . '" /> ';
    }
}

Source.

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.