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="https://wordpress.stackexchange.com/questions/151877/<?php the_field("image_toc', 'I am giving term id here'); ?>" />

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

1 Answer
1

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="https://wordpress.stackexchange.com/questions/151877/<?php the_field("image_toc', 'mytax_' . $termid ); ?>" />

In your case, this would amount to

<img src="https://wordpress.stackexchange.com/questions/151877/<?php the_field("image_toc', 'manufacture_1' ); ?>" />

Leave a Reply

Your email address will not be published. Required fields are marked *