Custom Taxonomy Filter Issues

I believe that the problem is with this line:

$var = &$query->query_vars[$tax_slug];
  1. &$query is not necessary, simle $query should be enaught.
  2. $query->query->vars[$tax_slug] returns not an ID of term, but term’s slug

So

$term = get_term_by( 'id', $var, $tax_slug );

should be changed to

$term = get_term_by( 'slug', $var, $tax_slug );

But is not necessary as you want to get a slug.

Further, pay attention. “Category” and “Post tag” taxonomies are not present as “category” and “tag”, but are stored as “category_name” and “tag”, so you have to transform $tax_slug accordingly inside your foreach loop. Eg:

$tax_slug_original = $tax_slug;
if( $tax_slug == 'category' ){
    $tax_slug = 'category_name';        
}
if( $tax_slug == 'post_tag' ){
    $tax_slug = 'tag';          
}
$var = $query->query_vars[$tax_slug];  
$tax_slug = $tax_slug_original;