Index: tests/phpunit/tests/query.php
===================================================================
--- tests/phpunit/tests/query.php	(revision 25538)
+++ tests/phpunit/tests/query.php	(working copy)
@@ -57,4 +57,25 @@
 			}
 		}
 	}
+
+	/**
+	 * @ticket 24785
+	 *
+	 */
+	function test_nested_loop_reset_postdata() {
+		$post_id = $this->factory->post->create();
+		$nested_post_id = $this->factory->post->create();
+
+		$first_query = new WP_Query( array( 'post__in' => array( $post_id ) ) );
+		while ( $first_query->have_posts() ) { $first_query->the_post();
+			$second_query = new WP_Query( array( 'post__in' => array( $nested_post_id ) ) );
+			while ( $second_query->have_posts() ) {
+				$second_query->the_post();
+				$this->assertEquals( get_the_ID(), $nested_post_id );
+			}
+			$first_query->reset_postdata();
+			$this->assertEquals( get_the_ID(), $post_id );
+		}
+
+	}
 }
\ No newline at end of file
Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 25539)
+++ src/wp-includes/query.php	(working copy)
@@ -115,10 +115,7 @@
  */
 function wp_reset_postdata() {
 	global $wp_query;
-	if ( !empty($wp_query->post) ) {
-		$GLOBALS['post'] = $wp_query->post;
-		setup_postdata($wp_query->post);
-	}
+	$wp_query->reset_postdata();
 }
 
 /*
@@ -3628,6 +3625,21 @@
 		global $wp_the_query;
 		return $wp_the_query === $this;
 	}
+
+	/**
+	 * After looping through a nested query, this function
+	 * restores the $post global to the current post in this query
+	 *
+	 * @since 3.7.0
+	 *
+	 * @return bool
+	 */
+	function reset_postdata() {
+		if ( ! empty( $this->post ) ) {
+			$GLOBALS['post'] = $this->post;
+			setup_postdata( $this->post );
+		}
+	}
 }
 
 /**
