Home › Forums › Front-end Issues › Can't Get Taxonomy Image to Display
Using CPT UI, I created custom taxonomies for products in my WooCommerce catalog, one of which is “Collection”. With the ACF plugin, I was able to assign an image to each collection. However, I can’t seem to get it to display on the front end.
I’ve tried all the different return formats and the corresponding code – found here https://www.advancedcustomfields.com/resources/image/ – but nothing seems to work. I can get some of the terms to display in text, but I cannot get an image to display.
Currently, I have the return format set to Image ID and I pasted the following code above the loop on the archive-product.php file –
<?php
$image = get_field(‘image’);
$size = ‘full’; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
Am I missing something?
When calling get_field for a term you must supply the $post_id argument in the correct format https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
I am also having the same issue, and have followed the logic on the link above. However, all of the images I need already exist in the Artists custom post type, and I don’t want to have to upload a new image to go with each Product Taxonomy. Each artist has a bio image and a banner image in their record. I need to associate the artist’s banner image with an item in the online store. It’s working, but it’s relying on a plugin that is no longer supported, so I want to get it to work using the existing images.
Here is is the structure: I have a WooCommerce store with a taxonomy named product_artist. I have custom post types of Artists. Each artist has custom image fields: artist-bio & artist-banner. I need to display the artist-banner field on the WooCommerce template page. I have this code, but don’t know how to finish it, to display the image:
<?php
/** Begin add artist banner to top of product page **/
if(is_single()) {
$terms = get_the_terms( $post->ID, ‘product_artist’ );
if ( !empty( $terms ) ){
// get the first term
$term = array_shift( $terms );
}
$artist = $term->slug;
$short_url = get_site_url();
$url = $short_url . ‘/artists/’ . $artist;
$postid = url_to_postid( $url );
$posttype = get_post_type($postid);
}
?>
I don’t know what to do from here to get the banner image to show on the page. This works, but the plugin used is outdated and we want to move away from it.
<?php
// adds the banner image from Artist post associated with this single product displayed
if (class_exists(‘MultiPostThumbnails’)
&& MultiPostThumbnails::has_post_thumbnail($posttype, ‘banner-image’, $postid)) :?>
“>
<?php MultiPostThumbnails::the_post_thumbnail($posttype, ‘banner-image’, $postid);?>
<?php else : ?>
<?php endif; /** end artist banner **/?>
Thank you for any help you can give!
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We demoed ACF 6.1 Beta during the most recent session of ACF Chat Fridays, highlighting the new ability to regenerate and clear labels, setting the Admin Menu Parent as a slug, and more. Catch the video replay in our latest summary. https://t.co/rHEpPVas64 pic.twitter.com/hB1XKTexXi
— Advanced Custom Fields (@wp_acf) March 23, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.