Display custom taxonomy child terms with category image on parent term archive


Staff member
I have a CPT with a custom taxonomy called 'equipment_cat'. I'm currently displaying the subcategories of a category on the category archive using the following code:

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    if ($term->parent == 0) {
wp_list_categories('taxonomy=equipment_cat&depth=1&show_count=0&title_li=&child_of=' . $term->term_id);
    } else {
wp_list_categories('taxonomy=equipment_cat&show_count=0&title_li=&child_of=' . $term->parent);

I'm using <a href="https://wordpress.org/plugins/taxonomy-images/" rel="nofollow noreferrer">Taxonomy Images</a> plugin to attach an image to each category. I've created a custom page template to display all top level categories with their images using this code:

    $terms = apply_filters( 'taxonomy-images-get-terms', '', array(
      'image_size' =&gt; 'medium',
      'term_args' =&gt; 'parent=0',
      'order' =&gt; 'ASC' ,
      'orderby' =&gt; 'title',
      'count'   =&gt; 2) );

    foreach( (array) $terms as $term){
        echo '&lt;div class="col-xs-6 col-sm-3 col-md-3"&gt;';
        echo '&lt;a href="' . esc_url( get_term_link( $term, $term-&gt;taxonomy ) ) . '"&gt;' .      wp_get_attachment_image( $term-&gt;image_id, 'medium' ) . '&lt;/a&gt;' . '&lt;h3&gt;'. sprintf(__('%s', 'my_localization_domain'), $term-&gt;name) . '&lt;/h3&gt;';
        echo '&lt;div class="description"&gt;';
        echo $term-&gt;description;
        echo '&lt;/div&gt;';
        echo '&lt;/div&gt;';

I would like to display the sub categories of a category in the category archive but also include the image that are attached to the subcategory.