Support

Account

Home Forums Front-end Issues Can't Get Taxonomy Image to Display

Solving

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!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Can't Get Taxonomy Image to Display’ is closed to new replies.