Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 25997)
+++ src/wp-includes/query.php	(working copy)
@@ -3248,20 +3248,25 @@
 		$this->queried_object_id = 0;
 
 		if ( $this->is_category || $this->is_tag || $this->is_tax ) {
-			$tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
+			if ( $this->is_category ) {
+				$term = get_term( $this->get( 'cat' ), 'category' );
+			} elseif ( $this->is_tag ) {
+				$term = get_term( $this->get( 'tag_id' ), 'post_tag' );
+			} else {
+				$tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
+				$query = reset( $tax_query_in_and );
 
-			$query = reset( $tax_query_in_and );
+				if ( 'term_id' == $query['field'] )
+					$term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
+				else
+					$term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
+			}
 
-			if ( 'term_id' == $query['field'] )
-				$term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
-			elseif ( $query['terms'] )
-				$term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
-
 			if ( ! empty( $term ) && ! is_wp_error( $term ) )  {
 				$this->queried_object = $term;
 				$this->queried_object_id = (int) $term->term_id;
 
-				if ( $this->is_category )
+				if ( $this->is_category && 'category' === $this->queried_object->taxonomy )
 					_make_cat_compat( $this->queried_object );
 			}
 		} elseif ( $this->is_post_type_archive ) {
Index: tests/phpunit/tests/query/conditionals.php
===================================================================
--- tests/phpunit/tests/query/conditionals.php	(revision 25997)
+++ tests/phpunit/tests/query/conditionals.php	(working copy)
@@ -652,8 +652,6 @@
 	}
 
 	function test_post_type_archive_with_tax_query() {
-		delete_option( 'rewrite_rules' );
-
 		$cpt_name = 'ptawtq';
 		register_post_type( $cpt_name, array(
 			'taxonomies' => array( 'post_tag', 'category' ),
@@ -662,6 +660,8 @@
 			'public' => true
 		) );
 
+		delete_option( 'rewrite_rules' );
+
 		$tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
 		$post_id = $this->factory->post->create( array( 'post_type' => $cpt_name ) );
 		wp_set_object_terms( $post_id, $tag_id, 'post_tag' );
@@ -677,6 +677,8 @@
 		$this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
 
 		remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) );
+
+		_unregister_post_type( $cpt_name );
 	}
 
 	function pre_get_posts_with_tax_query( &$query ) {
@@ -709,9 +711,86 @@
 		$this->assertEquals( get_queried_object(), get_post_type_object( 'post' ) );
 
 		remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) );
+		_unregister_post_type( $cpt_name );
 	}
 
 	function pre_get_posts_with_type_array( &$query ) {
 		$query->set( 'post_type', array( 'post', 'thearray' ) );
 	}
+
+	function test_tax_category_tax_query() {
+		register_taxonomy( 'testtax', 'post', array( 'query_var' => true ) );
+		delete_option( 'rewrite_rules' );
+
+		$tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
+		$cat_id = $this->factory->category->create( array( 'slug' => 'cat-slug' ) );
+		$tax_id = $this->factory->term->create( array( 'taxonomy' => 'testtax', 'slug' => 'tax-slug' ) );
+		$tax_id2 = $this->factory->term->create( array( 'taxonomy' => 'testtax', 'slug' => 'tax-slug2' ) );
+		$post_id = $this->factory->post->create();
+		wp_set_object_terms( $post_id, $tag_id, 'post_tag' );
+		wp_set_object_terms( $post_id, $cat_id, 'category' );
+		wp_set_object_terms( $post_id, array( $tax_id, $tax_id2 ), 'testtax' );
+
+		$cat = get_term( $cat_id, 'category' );
+		_make_cat_compat( $cat );
+
+		$tax = get_term( $tax_id, 'testtax' );
+		$tag = get_term( $tag_id, 'post_tag' );
+
+		add_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
+
+		// tag with tax added
+		$this->go_to( "/tag/tag-slug/" );
+		$this->assertQueryTrue( 'is_tag', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'tag_id' ) );
+		$this->assertEquals( get_queried_object(), $tag );
+
+		// tag + category with tax added
+		$this->go_to( "/tag/tag-slug/?cat=$cat_id" );
+		$this->assertQueryTrue( 'is_category', 'is_tag', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'cat' ) );
+		$this->assertNotEmpty( get_query_var( 'tag_id' ) );
+		$this->assertEquals( get_queried_object(), $cat );
+
+		// tag + category + tax with tax added
+		$this->go_to( "/tag/tag-slug/?cat=$cat_id&testtax=tax-slug2" );
+		$this->assertQueryTrue( 'is_category', 'is_tag', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'cat' ) );
+		$this->assertNotEmpty( get_query_var( 'tag_id' ) );
+		$this->assertEquals( get_queried_object(), $cat );
+
+		// category with tax added
+		$this->go_to( "/category/cat-slug/" );
+		$this->assertQueryTrue( 'is_category', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'cat' ) );
+		$this->assertEquals( get_queried_object(), $cat );
+
+		// tag + category with tax added
+		$this->go_to( "/tag/tag-slug/?cat=$cat_id" );
+		$this->assertQueryTrue( 'is_tag', 'is_category', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'tag_id' ) );
+		$this->assertNotEmpty( get_query_var( 'cat' ) );
+		$this->assertEquals( get_queried_object(), $cat );
+
+		// tax + tag with tax added
+		$this->go_to( "/testtax/tax-slug2/?tag_id=$tag_id" );
+		$this->assertQueryTrue( 'is_tag', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'tag_id' ) );
+		$this->assertEquals( get_queried_object(), $tag );
+
+		// tax + cat with tax added
+		$this->go_to( "/testtax/tax-slug2/?cat=$cat_id" );
+		$this->assertQueryTrue( 'is_category', 'is_archive' );
+		$this->assertNotEmpty( get_query_var( 'cat' ) );
+		$this->assertEquals( get_queried_object(), $cat );
+
+		remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
+	}
+
+	function pre_get_posts_tax_category_tax_query( &$query ) {
+		$term = get_term_by( 'slug', 'tax-slug', 'testtax' );
+		$query->set( 'tax_query', array(
+			array( 'taxonomy' => 'testtax', 'field' => 'term_id', 'terms' => $term->term_id )
+		) );
+	}
 }
