WordPress set post per page on Custom post type Taxonomy

function wpe_set_posts_per_page_for_towns_cpt( $query ) {

  if ( !is_admin() && $query->is_main_query() && is_tax() ) {
    $query->set( 'posts_per_page', '-1' );
  }
}
add_action( 'pre_get_posts', 'wpe_set_posts_per_page_for_towns_cpt' );