Display list of posts from taxonomy term, but display the latest post featured image


I’m trying to do a page where all posts from a custom post type list, divided by their taxonomy terms and having a big photo on top of the list (latest featured image from said term). Right now I have the following code, but it displays the wrong images (each term should show latest post’s featured image, and I’m not even sure why the images are just random, even in the wrong term):

<section id="" class="">  <?php      }     wp_reset_query();   $  tax = 'technology-category';      $  terms = get_terms( $  tax ,array(          'orderby'    => 'ID',         'order'      => 'ASC',         'hide_empty' => 0,     ));      //Loop throug each taxonomy terms,      foreach ( $  terms as $  term ) {          //Query argument for post     $  args = array(              'post_type' => 'technology', // Or Custom Post Type,              'order' => 'DESC',              'orderby' => 'date',             'taxonomy' => $  tax,             'term' => $  term->slug, // Query posts for each term based on term slug         );         $  query = new WP_Query( $  args );          $  posts = $  query->get_posts();          ?>  <div class="container-fluid tech-cat-item py-5">     <div class="container">     <div class="row align-items-center pb-3">     <div class="col-1">     <img class="img-fluid" src="<?php echo z_taxonomy_image_url($  term->term_id); ?>"> </div> <div class="col-11">     <h3><?php echo $  term->name;?></h3> </div> </div> <?php //Do query to get image?        $  ga_item = array(             'post_type' => 'technology',               'order' => 'DESC',              'orderby' => 'date',             'taxonomy' => $  tax,             'term' => $  term->slug,              'posts_per_page' => '1', //just one because only need the latest post's featured image );        $  ga_query = new WP_Query( $  ga_item );         $  ga_posts = $  query->get_posts();     if ( $  ga_query->have_posts() ) {     while ( $  ga_query->have_posts() ) { $  ga_query->the_post(); ?>     <div class="row ga-panel py-5">     <div class="col-12">         <?php          $  ga_url = get_the_post_thumbnail_url($  post->ID,'full'); ?>         <img class="img-fluid ga-img" src="<?php echo esc_url($  ga_url);?>">     </div>     </div> <?php } } wp_reset_query(); ?>     <div class="row">         <?php          if ( $  posts ) {          foreach ( $  posts as $  post ) { ?>              <div class="col-4 ga-links">                 <a href="<?php the_permalink( $  post->ID ); ?>" data-swap="<?php echo esc_url($  ga_url);?>" > <?php echo $  post->post_title; ?></a>             </div>          <?php                     }         }        ?> </div> </div> </div>   <?php  }  wp_reset_query(); ?>                      </section>