Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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!

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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>';
share|improve this answer
    
Thank you very much Milo - That did the trick! –  Mikkel Tschentscher Jan 27 '13 at 16:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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