My Custom Post Type AJAX Query is Returning no posts – why?

When I run this query on posts_type => "posts" it works just fine. But when I add my custom post type ‘post_type’ => ‘case-studies’, I get no results.

The custom post type has a custom taxonomy set up of ‘case_study_categories’. Can anyone spot what is wrong? I’ve been looking at this for 3 hours and just don’t understand why it isn’t working.

filter-posts.php:

<?php  function ajax_filter_posts_scripts() {   // Enqueue script   wp_enqueue_script('afp_script', get_template_directory_uri() . '/js/ajax/filter-posts.js', array('jquery'), null, false);    wp_localize_script( 'afp_script', 'afp_vars', array(         'afp_nonce' => wp_create_nonce( 'afp_nonce' ), // Create nonce which we later will use to verify AJAX request         'afp_ajax_url' => admin_url( 'admin-ajax.php' ),       )   ); } add_action('wp_enqueue_scripts', 'ajax_filter_posts_scripts', 100);  // Script for getting posts function ajax_filter_get_posts() {    // Verify nonce   if( !isset( $  _POST['afp_nonce'] ) || !wp_verify_nonce( $  _POST['afp_nonce'], 'afp_nonce' ) )     die('Permission denied');    $  data = $  _POST['data'];   $  taxonomy = $  data['taxonomy'];   $  posts_per_page = $  data['posts_per_page'];      $  args = array(     'post_type' => 'case-studies',     'posts_per_page' => $  posts_per_page, );    // If taxonomy is not set, remove key from array and get all posts   if( $  taxonomy ) {     $  args['category_name'] = $  taxonomy;   }    $  query = new WP_Query( $  args );   $  max = $  query->max_num_pages;?>    <?php if ( $  query->have_posts() ) :      // Used to count the posts and compare to max to hide and show load more button;     $  index = 1;      while ( $  query->have_posts() ) : $  query->the_post();       $  index++;       $  featured_img_url_medium = get_the_post_thumbnail_url(get_the_ID(),'medium_large');       $  id = get_the_ID();       $  category = get_the_category();       $  category_name = $  category[0]->cat_name;?>       <a href="<?= get_permalink(); ?>" title="Read - <?php the_title(); ?>" class="dynamic-blogs__card card">         <div class="news-image-container">           <div class="hover-read-more">             <div class="text">               <i class="fal fa-chevron-circle-right"></i>               <p>Read Now</p>             </div>           </div>           <img class="card-image lazy" src="<?= $  featured_img_url_medium; ?>" alt="<?php the_title(); ?>" loading="lazy">         </div>          <div class="card-text-container">           <?php if( $  category_name ) {             echo '<p class="card-category">' . $  category_name . '</p>';           } ?>           <?= the_title('<h3 class="">', '</h3>'); ?>         </div>       </a><!-- Card END -->      <?php endwhile; ?>     <?php if($  index <= $  max ): ?>       <div class="dynamic-blogs__load-more py">         <div class="btn -ghost js-tax-filter" number="12">Load More</div>       </div>     <?php endif;  ?>   <?php else: ?>     <h2>No posts found</h2>   <?php endif;    die(); }  add_action('wp_ajax_filter_posts', 'ajax_filter_get_posts'); add_action('wp_ajax_nopriv_filter_posts', 'ajax_filter_get_posts');  ?>