I've set up a custom field which appears in a taxonomy terms page. I am trying pull an image associated with the custom taxonomy term directly

However the page in which it is being displayed is a template page. I think I need to pass the post ID before pulling the specific image, but how do you do that for a custom taxonomy?

The custom taxonomy is 'manufacture', and the term id is e.g 1, the image field id is 'image_toc' and I have set ACF to image url. I've read the page on "how-to/how-to-get-values-from-a-taxonomy-term/" but I don't really understand what I'm supposed to replace with what. I am using things along the lines of:

<img src="<?php the_field('image_toc', 'I am giving term id here'); ?>" />

But nothing is happening. No image and no path in the source code.

  • What's the name of the custom taxonomy? – engelen Jun 26 '14 at 12:24
  • The custom taxonomy is 'manufacture', and the term id is 1 – Jamil Ahmed Jun 26 '14 at 12:38

To retrieve a field from ACF for a term (instead of, for example, a post), you should use the taxonomy name, followed by an underscore, followed by the term ID instead of the post ID when calling the_field or get_field. Assuming you want to retrieve the field image_toc for the taxonomy mytax and term ID $termid that would be:

<img src="<?php the_field( 'image_toc', 'mytax_' . $termid ); ?>" />

In your case, this would amount to

<img src="<?php the_field( 'image_toc', 'manufacture_1' ); ?>" />
|improve this answer|||||
  • Its working great and exactly I need. I cannot give you +1 because of privilege. – Jamil Ahmed Jun 26 '14 at 13:05
  • I'm glad to hear that, you're welcome! – engelen Jun 26 '14 at 13:06

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