Site icon Hip-Hop Website Design and Development

Why is my custom taxonomy image not displaying?

I have created a custom image taxonomy field in WordPress using CMB2. I cannot get the images to display for website visitors even though my code uses get_term_meta. (The taxonomy images are amenity icons such as WiFi, shower head, electricity etc).

What am I doing wrong?

Relevant (not working) code in single-accommodation.php:

<?php
$term_id = get_queried_object()->term_id;
$tax_image = get_term_meta( $term_id, 'custom_taxonomy_image', true );

if ( $tax_image ) {
    printf( '<div class="icon"><img src=$s /></div>', $tax_image );
}
?>

I’m sure i’d need a foreach somewhere, like this:

<ul class="amenity-icons">
<?php
foreach( $terms as $term => $icon ) {
   if( isset( $term ) ) {
      echo '<li>' . $icon . '</li>';
   }
}
?>
</ul>

I can successfully retrieve the term list as words using:

<?php the_terms( get_the_ID(), 'amenity' ); ?>