In your code, I have found 2 issues:
1) In your ajax function ajax_filter_get_posts(), you have missed tax_query in your arg.
Your ajax function ajax_filter_get_posts() should be as below:
function ajax_filter_get_posts( $taxonomy ) {
// Verify nonce
if( !isset( $_POST['afp_nonce'] ) || !wp_verify_nonce( $_POST['afp_nonce'], 'afp_nonce' ) )
die('Permission denied');
$taxonomy = $_POST['taxonomy'];
// WP Query
$args = array(
'exclude' => '1,2,4,5,7,8,9,10,11,12',
'post_type' => 'post',
'nopaging' => true, // show all posts in one go
);
echo $taxonomy;
// If taxonomy is not set, remove key from array and get all posts
if( !$taxonomy ) {
unset( $args['tag'] );
}else{
// This is the code which you are missing. You need to add taxonomy query if taxonomy is set.
$arg['tax_query']= array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( $taxonomy ),
'include_children' => true, // set true if you want post of its child category also
'operator' => 'IN'
),
);
}
$query = new WP_Query( $args );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-md-4">
<div class="img-thumb">
<a href="https://wordpress.stackexchange.com/questions/260141/<?php the_field("link_do_case'); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<small><?php the_title(); ?></small>
</div>
<?php endwhile; ?>
<?php else: ?>
<h2>Case não encontrado</h2>
<?php endif;
die();
}
2) In your structure page, replace the tag line link with below line:
echo '<option value="' . $term_link . '" class="tax-filter" title="'.$term->slug.'">' . $term->name . '</option> ';
3) In your jQuery, change the way you are getting selected taxonomy value:
var selecetd_taxonomy = jQuery(this).find('option:selected').attr("title");
By doing above 3 changes you will get post of only selected category.
Hope this will help you.