问题
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