Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 25248)
+++ src/wp-includes/query.php	(working copy)
@@ -58,6 +58,36 @@
 }
 
 /**
+ * Retrieve the currently-queried objects. Wrapper for $wp_query->get_queried_objects()
+ *
+ * @uses WP_Query::get_queried_objects
+ *
+ * @since 3.7.0
+ * @access public
+ *
+ * @return object|null
+ */
+function get_queried_objects() {
+	global $wp_query;
+	return $wp_query->get_queried_objects();
+}
+
+/**
+ * Retrieve IDs of the current queried objects. Wrapper for $wp_query->get_queried_object_ids()
+ *
+ * @uses WP_Query::get_queried_object_ids()
+ *
+ * @since 3.7.0
+ * @access public
+ *
+ * @return int
+ */
+function get_queried_object_ids() {
+	global $wp_query;
+	return $wp_query->get_queried_object_ids();
+}
+
+/**
  * Set query variable.
  *
  * @see WP_Query::set()
@@ -896,6 +926,24 @@
 	var $queried_object_id;
 
 	/**
+	 * Holds the data for the objects that are queried.
+	 *
+	 * @since 3.7.0
+	 * @access public
+	 * @var array
+	 */
+	var $queried_objects;
+
+	/**
+	 * The IDs of the queried objects.
+	 *
+	 * @since 3.7.0
+	 * @access public
+	 * @var array
+	 */
+	var $queried_object_ids;
+
+	/**
 	 * Get post database query.
 	 *
 	 * @since 2.0.1
@@ -3036,62 +3084,105 @@
 	 * @return object
 	 */
 	function get_queried_object() {
-		if ( isset($this->queried_object) )
-			return $this->queried_object;
+		$this->get_queried_objects();
+		return $this->queried_object;
+	}
 
-		$this->queried_object = null;
-		$this->queried_object_id = 0;
+	/**
+	 * Retrieve ID of the current queried object.
+	 *
+	 * @since 1.5.0
+	 * @access public
+	 *
+	 * @return int
+	 */
+	function get_queried_object_id() {
+		$this->get_queried_objects();
+		return $this->queried_object_id;
+	}
 
+ 	/**
+	 * Retrieve queried objects.
+	 *
+	 * If queried objects is not set, then the queried object will be set from
+	 * the categories, tags, taxonomies, posts page, single post, page, or author
+	 * query variable. After it is set up, it will be returned.
+	 *
+	 * @since 3.7.0
+	 * @access public
+	 *
+	 * @return array
+	 */
+	public function get_queried_objects() {
+		if ( isset( $this->queried_objects ) )
+			return $this->queried_objects;
+
+		$this->queried_objects = array();
+		$this->queried_object_ids = array();
+
 		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' );
 
+			$terms = array();
 			$query = reset( $tax_query_in_and );
 
-			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 ( $query['terms'] ) {
+				foreach ( $query['terms'] as $term ) {
+					$term = get_term_by( $query['field'], $term, $query['taxonomy'] );
+					if ( $term && ! is_wp_error( $term ) ) {
+						$terms[] = $term;
+					}
+				}
+			}
 
-			if ( ! empty( $term ) && ! is_wp_error( $term ) )  {
-				$this->queried_object = $term;
-				$this->queried_object_id = (int) $term->term_id;
+			if ( ! empty( $terms ) )  {
+				if ( $this->is_category ) {
+					foreach ( $terms as &$category ) {
+						_make_cat_compat( $category );
+					}
+					unset( $category );
+				}
 
-				if ( $this->is_category )
-					_make_cat_compat( $this->queried_object );
+				$this->queried_objects = $terms;
+				$this->queried_object_ids = wp_list_pluck( $this->queried_objects, 'term_id' );
 			}
 		} elseif ( $this->is_post_type_archive ) {
-			$this->queried_object = get_post_type_object( $this->get('post_type') );
+			$post_types = (array) $this->get( 'post_type' );
+			foreach ( $post_types as $post_type ) {
+				$this->queried_objects[] = get_post_type_object( $post_type );
+			}
 		} elseif ( $this->is_posts_page ) {
-			$page_for_posts = get_option('page_for_posts');
-			$this->queried_object = get_post( $page_for_posts );
-			$this->queried_object_id = (int) $this->queried_object->ID;
-		} elseif ( $this->is_singular && !is_null($this->post) ) {
-			$this->queried_object = $this->post;
-			$this->queried_object_id = (int) $this->post->ID;
+			$page_for_posts = get_option( 'page_for_posts' );
+			$this->queried_objects[] = get_post( $page_for_posts );
+			$this->queried_object_ids = wp_list_pluck( $this->queried_objects, 'ID' );
+		} elseif ( $this->is_singular && ! is_null( $this->post ) ) {
+			$this->queried_objects[] = $this->post;
+			$this->queried_object_ids = wp_list_pluck( $this->queried_objects, 'ID' );
 		} elseif ( $this->is_author ) {
-			$this->queried_object_id = (int) $this->get('author');
-			$this->queried_object = get_userdata( $this->queried_object_id );
+			$this->queried_object_ids = array_map( 'absint', (array) $this->get( 'author' ) );
+			foreach ( $this->queried_object_ids as $user_id ) {
+				$this->queried_objects[] = get_userdata( $user_id );
+			}
 		}
 
-		return $this->queried_object;
+		// back-compat for get_queried_object and get_queried_object_id
+		$this->queried_object = ( ! empty( $this->queried_objects ) ) ? reset( $this->queried_objects ) : null;
+		$this->queried_object_id = ( ! empty( $this->queried_object_ids ) ) ? reset( $this->queried_object_ids ) : 0;
+
+		return $this->queried_objects;
 	}
 
 	/**
-	 * Retrieve ID of the current queried object.
+	 * Retrieve IDs of the current queried objects.
 	 *
-	 * @since 1.5.0
+	 * @since 3.7.0
 	 * @access public
 	 *
-	 * @return int
+	 * @return array
 	 */
-	function get_queried_object_id() {
-		$this->get_queried_object();
-
-		if ( isset($this->queried_object_id) ) {
-			return $this->queried_object_id;
-		}
-
-		return 0;
+	public function get_queried_object_ids() {
+		$this->get_queried_objects();
+		return $this->queried_object_ids;
 	}
 
 	/**
Index: tests/phpunit/data/images/a2-small-100x75.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: tests/phpunit/tests/query/results.php
===================================================================
--- tests/phpunit/tests/query/results.php	(revision 25248)
+++ tests/phpunit/tests/query/results.php	(working copy)
@@ -13,6 +13,12 @@
 	function setUp() {
 		parent::setUp();
 
+		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
+		$GLOBALS['wp_rewrite']->init();
+		create_initial_taxonomies();
+		register_post_type( 'cpt', array( 'public' => true, 'has_archive' => true ) );
+		flush_rewrite_rules();
+
 		$cat_a = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) );
 		$cat_b = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) );
 		$cat_c = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-c' ) );
@@ -486,4 +492,81 @@
 		$author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) );
 		$this->assertEqualSets( array( $author_1 ), $author_ids );
 	}
+
+	/**
+	 * Tag archives
+	 * @ticket 5358
+	 */
+	function test_queried_objects_tags() {
+		// Single tag archive
+		$tag_one_id = $this->factory->tag->create();
+		$tag_one = get_term( $tag_one_id, 'post_tag' );
+		$this->go_to( get_term_link( $tag_one, 'post_tag' ) );
+
+		$this->assertTrue( is_archive() && is_tag() );
+		$this->assertEquals( get_queried_object_id(), $tag_one_id );
+		$this->assertEquals( get_queried_object(), $tag_one );
+		$this->assertEquals( get_queried_object_ids(), array( $tag_one_id ) );
+		$this->assertEquals( get_queried_objects(), array( $tag_one ) );
+
+		// Multiple tags archive
+		$tag_two_id = $this->factory->tag->create();
+		$tag_two = get_term( $tag_two_id, 'post_tag' );
+		$this->go_to( "/tag/{$tag_one->slug}+{$tag_two->slug}/" );
+
+		$this->assertTrue( is_archive() && is_tag() );
+		$this->assertEquals( get_queried_object_id(), $tag_one_id );
+		$this->assertEquals( get_queried_object(), $tag_one );
+		$this->assertEquals( get_queried_object_ids(), array( $tag_one_id, $tag_two_id ) );
+		$this->assertEquals( get_queried_objects(), array( $tag_one, $tag_two ) );
+	}
+
+	/**
+	 * Post type archives
+	 * @ticket 5358
+	 */
+	function test_queried_objects_post_types() {
+		$post_type = get_post_type_object( 'cpt' );
+		$this->factory->post->create( array( 'post_type' => 'cpt' ) );
+		$this->go_to( get_post_type_archive_link( 'cpt' ) );
+
+		$this->assertTrue( is_archive() && is_post_type_archive() );
+		$this->assertEquals( get_queried_object_id(), null );
+		$this->assertEquals( get_queried_object(), $post_type );
+		$this->assertEquals( get_queried_object_ids(), array() );
+		$this->assertEquals( get_queried_objects(), array( $post_type ) );
+	}
+
+	/**
+	 * Posts
+	 * @ticket 5358
+	 */
+	function test_queried_objects_posts() {
+		$post_id = $this->factory->post->create();
+		$post = get_post( $post_id );
+		$this->go_to( get_permalink( $post->ID ) );
+
+		$this->assertTrue( is_single() && is_singular() );
+		$this->assertEquals( get_queried_object_id(), $post->ID );
+		$this->assertEquals( get_queried_object(), $post );
+		$this->assertEquals( get_queried_object_ids(), array( $post->ID ) );
+		$this->assertEquals( get_queried_objects(), array( $post ) );
+	}
+
+	/**
+	 * Authors
+	 * @ticket 5358
+	 */
+	function test_queried_objects_authors() {
+		$user_id = $this->factory->user->create();
+		$user = get_userdata( $user_id );
+		$this->factory->post->create( array( 'author' => $user->ID ) );
+		$this->go_to( get_author_posts_url( $user->ID ) );
+
+		$this->assertTrue( is_archive() && is_author() );
+		$this->assertEquals( get_queried_object_id(), $user->ID );
+		$this->assertEquals( get_queried_object(), $user );
+		$this->assertEquals( get_queried_object_ids(), array( $user->ID ) );
+		$this->assertEquals( get_queried_objects(), array( $user ) );
+	}
 }
