diff --git tests/phpunit/tests/post/query.php tests/phpunit/tests/post/query.php
index 0539edc..8437841 100644
--- tests/phpunit/tests/post/query.php
+++ tests/phpunit/tests/post/query.php
@@ -1477,6 +1477,83 @@ class Tests_Post_Query extends WP_UnitTestCase {
 	}
 
 	/**
+	 * @ticket 29031
+	 * @group taxonomy
+	 */
+	public function test_tax_query_field_id_terms_order() {
+		register_taxonomy( 'movie_genre', 'post' );
+		register_taxonomy( 'actors', 'post' );
+		$posts = $this->factory->post->create_many( 4 );
+
+		$mg_term = $this->factory->term->create( array(
+			'taxonomy' => 'movie_genre',
+			'slug' => 'action',
+		) );
+
+		$a_term_1 = $this->factory->term->create( array(
+			'taxonomy' => 'actors',
+		) );
+
+		$a_term_2 = $this->factory->term->create( array(
+			'taxonomy' => 'actors',
+		) );
+
+		// a_term_1 does not have any posts.
+		wp_set_object_terms( $posts[0], $mg_term, 'movie_genre' );
+		wp_set_object_terms( $posts[0], $a_term_2, 'actors' );
+
+		wp_set_object_terms( $posts[1], $mg_term, 'movie_genre' );
+		wp_set_object_terms( $posts[2], $a_term_2, 'actors' );
+
+		$query = new WP_Query( array(
+			'fields' => 'ids',
+			'update_post_term_cache' => false,
+			'update_post_meta_cache' => false,
+			'relation' => 'AND',
+			'tax_query' => array(
+				array(
+					'taxonomy' => 'movie_genre',
+					'field' => 'slug',
+					'terms' => array( 'action' ),
+				),
+				array(
+					'taxonomy' => 'actors',
+					'field' => 'id',
+					'terms' => array( $a_term_1, $a_term_2 ),
+					'operator' => 'IN',
+				)
+			),
+		) );
+
+		$found = $query->get_posts();
+		$this->assertEqualSets( array( $posts[0] ), $found );
+
+		// Try again, with the 'actors' terms reversed in order.
+		$query = new WP_Query( array(
+			'fields' => 'ids',
+			'update_post_term_cache' => false,
+			'update_post_meta_cache' => false,
+			'relation' => 'AND',
+			'tax_query' => array(
+				array(
+					'taxonomy' => 'movie_genre',
+					'field' => 'slug',
+					'terms' => array( 'action' ),
+				),
+				array(
+					'taxonomy' => 'actors',
+					'field' => 'id',
+					'terms' => array( $a_term_2, $a_term_1 ),
+					'operator' => 'IN',
+				)
+			),
+		) );
+
+		$found = $query->get_posts();
+		$this->assertEqualSets( array( $posts[0] ), $found );
+	}
+
+	/**
 	 * @group taxonomy
 	 */
 	public function test_tax_query_include_children() {
