Pulling in image from custom taxonomy with ACF

爷,独闯天下 提交于 2019-12-25 02:57:40

问题


So here is what i'm trying to do. I have created a custom taxonomy called "country" and within that custom taxonomy I have categories of different countries like, USA, France, Germany, England and so on. I created a ACF(Advance custom field) Field Group that lets me add a image to each country, I have this called "flag". So when I make a post and I check the country under the custom taxonomy I need to pull that image (flag) associated with that category and display it on my page.

I have seen lots of post on what im looking to do but I cant seem to get any to work. Here is the code im TRYING to use.

<?php
$attachment_id = get_field( 'flag', 'country_' . $queried_object->term_id );
$thumb = wp_get_attachment_image_src( $attachment_id );

var_dump($attachment_id);
?>
<p><img src="<?php echo $thumb[0]; ?>" /></p>

Its bring back a "NULL" and not my image id.

Any ideas on what i'm doing wrong or any advice you and lend me?


回答1:


have you defined $queried_object?

EDIT: TRY THIS OUT

<?php
$term =$wp_query->queried_object;
$attachment_id = get_field( 'flag', 'country_' . $term->term_id );
$thumb = wp_get_attachment_image_src( $attachment_id );

var_dump($attachment_id);
?>
<p><img src="<?php echo $thumb[0]; ?>" /></p>


来源:https://stackoverflow.com/questions/29704246/pulling-in-image-from-custom-taxonomy-with-acf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!