2

I'm trying to display a list of all my custom taxonomy terms with an image field that I have created in ACF. The ACF image field I have is <img src="<?php the_field('brochure_logo'); ?>">, but how can I display that image in my code below? I have left a gap where the field needs to go, but I can't seem to output the image URL.

$taxonomy = 'brochure_categories';
$tax_terms = get_terms( $taxonomy );
?>
<ul class="downloadGrid">
<?php
foreach ( $tax_terms as $tax_term ) {
    echo '<li>';
    echo '<a href="' . esc_attr( get_term_link( $tax_term, $taxonomy ) ) . 
        '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . 
        '" ' . '>';

    echo  '<img src="    " >';
    echo  $tax_term->name;
    echo '</a>';
    echo '</li>';
}

2 Answers 2

4

You can pass the term object as the second parameter to the_field/get_field.

echo '<img src="' . get_field( 'brochure_logo', $tax_term ) . '">';
1

In the settings from that field you can select to output the image URL. If it returns a object, use:

$img = get_field( 'brochure_logo' );

And to output the URL, use:

echo $img[0]['url']

Not the answer you're looking for? Browse other questions tagged or ask your own question.