Show custom field from custom taxanomy term on custom post type

I need to show a list of custom taxanomy terms assigned to the current post type with a name and a custom field. (Created with Advanced Custom Fields)

Currently I use the following code, to show a list of the custom taxanomy terms assigned to the current post:

Read More
echo '<ul class="taxanomy-name">';
echo get_the_term_list( $post->ID, 'taxanomy-name', '<li>', ',</li><li>', '</li>' );
echo '</ul>';

Allthough I want to show a custom field from each taxanomy term along with the name.
The code for showing the custom field on each taxanomy term page template is:

the_field('custom-field-name', 'taxanomy-name_ID');

My question is, how do i show the custom field, along with the custom taxanomy term name on the list?

Example:

<ul>
 <li>
  Taxanomy Term Name 1
  <img src="custom-taxanomy-term-1-custom-field-image">
 </li>

 <li>
  Taxanomy Term Name 2
  <img src="custom-taxanomy-term-2-custom-field-image">
 </li>
</ul>

I hope you can help me..
It’s been bugging me for hours.
Thanks!

Related posts

Leave a Reply

1 comment

  1. Use the get_the_terms function instead so you can build the list manually and access the term_id for each term.

    $terms = get_the_terms( $post->ID, 'taxanomy-name' );
    echo '<ul>';
    foreach( $terms as $term ):
        echo '<li>';
        echo $term->name;
        the_field( 'custom-field-name', 'taxanomy-name_' . $term->term_id );
        echo '</li>';
    endforeach;
    echo '</ul>';