wp/wp-includes/class-wp-query.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/class-wp-query.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/class-wp-query.php	Tue Sep 27 16:37:53 2022 +0200
@@ -18,7 +18,7 @@
 class WP_Query {
 
 	/**
-	 * Query vars set by the user
+	 * Query vars set by the user.
 	 *
 	 * @since 1.5.0
 	 * @var array
@@ -26,7 +26,7 @@
 	public $query;
 
 	/**
-	 * Query vars, after parsing
+	 * Query vars, after parsing.
 	 *
 	 * @since 1.5.0
 	 * @var array
@@ -34,7 +34,7 @@
 	public $query_vars = array();
 
 	/**
-	 * Taxonomy query, as passed to get_tax_sql()
+	 * Taxonomy query, as passed to get_tax_sql().
 	 *
 	 * @since 3.1.0
 	 * @var WP_Tax_Query A taxonomy query instance.
@@ -42,7 +42,7 @@
 	public $tax_query;
 
 	/**
-	 * Metadata query container
+	 * Metadata query container.
 	 *
 	 * @since 3.2.0
 	 * @var WP_Meta_Query A meta query instance.
@@ -50,7 +50,7 @@
 	public $meta_query = false;
 
 	/**
-	 * Date query container
+	 * Date query container.
 	 *
 	 * @since 3.7.0
 	 * @var WP_Date_Query A date query instance.
@@ -92,7 +92,7 @@
 	public $posts;
 
 	/**
-	 * The amount of posts for the current query.
+	 * The number of posts for the current query.
 	 *
 	 * @since 1.5.0
 	 * @var int
@@ -135,7 +135,7 @@
 	public $comments;
 
 	/**
-	 * The amount of comments for the posts.
+	 * The number of comments for the posts.
 	 *
 	 * @since 2.2.0
 	 * @var int
@@ -159,7 +159,7 @@
 	public $comment;
 
 	/**
-	 * The amount of found posts for the current query.
+	 * The number of found posts for the current query.
 	 *
 	 * If limit clause was not used, equals $post_count.
 	 *
@@ -169,7 +169,7 @@
 	public $found_posts = 0;
 
 	/**
-	 * The amount of pages.
+	 * The number of pages.
 	 *
 	 * @since 2.1.0
 	 * @var int
@@ -177,7 +177,7 @@
 	public $max_num_pages = 0;
 
 	/**
-	 * The amount of comment pages.
+	 * The number of comment pages.
 	 *
 	 * @since 2.7.0
 	 * @var int
@@ -536,10 +536,10 @@
 	 * @since 2.1.0
 	 * @since 4.5.0 Removed the `comments_popup` public query variable.
 	 *
-	 * @param array $array Defined query variables.
+	 * @param array $query_vars Defined query variables.
 	 * @return array Complete query variables with undefined ones filled in empty.
 	 */
-	public function fill_query_vars( $array ) {
+	public function fill_query_vars( $query_vars ) {
 		$keys = array(
 			'error',
 			'm',
@@ -580,8 +580,8 @@
 		);
 
 		foreach ( $keys as $key ) {
-			if ( ! isset( $array[ $key ] ) ) {
-				$array[ $key ] = '';
+			if ( ! isset( $query_vars[ $key ] ) ) {
+				$query_vars[ $key ] = '';
 			}
 		}
 
@@ -604,11 +604,12 @@
 		);
 
 		foreach ( $array_keys as $key ) {
-			if ( ! isset( $array[ $key ] ) ) {
-				$array[ $key ] = array();
+			if ( ! isset( $query_vars[ $key ] ) ) {
+				$query_vars[ $key ] = array();
 			}
 		}
-		return $array;
+
+		return $query_vars;
 	}
 
 	/**
@@ -630,117 +631,137 @@
 	 * @param string|array $query {
 	 *     Optional. Array or string of Query parameters.
 	 *
-	 *     @type int          $attachment_id           Attachment post ID. Used for 'attachment' post_type.
-	 *     @type int|string   $author                  Author ID, or comma-separated list of IDs.
-	 *     @type string       $author_name             User 'user_nicename'.
-	 *     @type int[]        $author__in              An array of author IDs to query from.
-	 *     @type int[]        $author__not_in          An array of author IDs not to query from.
-	 *     @type bool         $cache_results           Whether to cache post information. Default true.
-	 *     @type int|string   $cat                     Category ID or comma-separated list of IDs (this or any children).
-	 *     @type int[]        $category__and           An array of category IDs (AND in).
-	 *     @type int[]        $category__in            An array of category IDs (OR in, no children).
-	 *     @type int[]        $category__not_in        An array of category IDs (NOT in).
-	 *     @type string       $category_name           Use category slug (not name, this or any children).
-	 *     @type array|int    $comment_count           Filter results by comment count. Provide an integer to match
-	 *                                                 comment count exactly. Provide an array with integer 'value'
-	 *                                                 and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
-	 *                                                 compare against comment_count in a specific way.
-	 *     @type string       $comment_status          Comment status.
-	 *     @type int          $comments_per_page       The number of comments to return per page.
-	 *                                                 Default 'comments_per_page' option.
-	 *     @type array        $date_query              An associative array of WP_Date_Query arguments.
-	 *                                                 See WP_Date_Query::__construct().
-	 *     @type int          $day                     Day of the month. Default empty. Accepts numbers 1-31.
-	 *     @type bool         $exact                   Whether to search by exact keyword. Default false.
-	 *     @type string       $fields                  Post fields to query for. Accepts:
-	 *                                                 - '' Returns an array of complete post objects (`WP_Post[]`).
-	 *                                                 - 'ids' Returns an array of post IDs (`int[]`).
-	 *                                                 - 'id=>parent' Returns an associative array of parent post IDs,
-	 *                                                   keyed by post ID (`int[]`).
-	 *                                                 Default ''.
-	 *     @type int          $hour                    Hour of the day. Default empty. Accepts numbers 0-23.
-	 *     @type int|bool     $ignore_sticky_posts     Whether to ignore sticky posts or not. Setting this to false
-	 *                                                 excludes stickies from 'post__in'. Accepts 1|true, 0|false.
-	 *                                                 Default false.
-	 *     @type int          $m                       Combination YearMonth. Accepts any four-digit year and month
-	 *                                                 numbers 1-12. Default empty.
-	 *     @type string       $meta_compare            Comparison operator to test the 'meta_value'.
-	 *     @type string       $meta_compare_key        Comparison operator to test the 'meta_key'.
-	 *     @type string       $meta_key                Custom field key.
-	 *     @type array        $meta_query              An associative array of WP_Meta_Query arguments. See WP_Meta_Query.
-	 *     @type string       $meta_value              Custom field value.
-	 *     @type int          $meta_value_num          Custom field value number.
-	 *     @type string       $meta_type_key           Cast for 'meta_key'. See WP_Meta_Query::construct().
-	 *     @type int          $menu_order              The menu order of the posts.
-	 *     @type int          $monthnum                The two-digit month. Default empty. Accepts numbers 1-12.
-	 *     @type string       $name                    Post slug.
-	 *     @type bool         $nopaging                Show all posts (true) or paginate (false). Default false.
-	 *     @type bool         $no_found_rows           Whether to skip counting the total rows found. Enabling can improve
-	 *                                                 performance. Default false.
-	 *     @type int          $offset                  The number of posts to offset before retrieval.
-	 *     @type string       $order                   Designates ascending or descending order of posts. Default 'DESC'.
-	 *                                                 Accepts 'ASC', 'DESC'.
-	 *     @type string|array $orderby                 Sort retrieved posts by parameter. One or more options may be
-	 *                                                 passed. To use 'meta_value', or 'meta_value_num',
-	 *                                                 'meta_key=keyname' must be also be defined. To sort by a
-	 *                                                 specific `$meta_query` clause, use that clause's array key.
-	 *                                                 Accepts 'none', 'name', 'author', 'date', 'title',
-	 *                                                 'modified', 'menu_order', 'parent', 'ID', 'rand',
-	 *                                                 'relevance', 'RAND(x)' (where 'x' is an integer seed value),
-	 *                                                 'comment_count', 'meta_value', 'meta_value_num', 'post__in',
-	 *                                                 'post_name__in', 'post_parent__in', and the array keys
-	 *                                                 of `$meta_query`. Default is 'date', except when a search
-	 *                                                 is being performed, when the default is 'relevance'.
-	 *     @type int          $p                       Post ID.
-	 *     @type int          $page                    Show the number of posts that would show up on page X of a
-	 *                                                 static front page.
-	 *     @type int          $paged                   The number of the current page.
-	 *     @type int          $page_id                 Page ID.
-	 *     @type string       $pagename                Page slug.
-	 *     @type string       $perm                    Show posts if user has the appropriate capability.
-	 *     @type string       $ping_status             Ping status.
-	 *     @type int[]        $post__in                An array of post IDs to retrieve, sticky posts will be included.
-	 *     @type int[]        $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
-	 *                                                 separated IDs will NOT work.
-	 *     @type string       $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
-	 *     @type string[]     $post_name__in           An array of post slugs that results must match.
-	 *     @type int          $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
-	 *                                                 top-level pages.
-	 *     @type int[]        $post_parent__in         An array containing parent page IDs to query child pages from.
-	 *     @type int[]        $post_parent__not_in     An array containing parent page IDs not to query child pages from.
-	 *     @type string|array $post_type               A post type slug (string) or array of post type slugs.
-	 *                                                 Default 'any' if using 'tax_query'.
-	 *     @type string|array $post_status             A post status (string) or array of post statuses.
-	 *     @type int          $posts_per_page          The number of posts to query for. Use -1 to request all posts.
-	 *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
-	 *                                                 'posts_per_page' when is_archive(), or is_search() are true.
-	 *     @type string       $s                       Search keyword(s). Prepending a term with a hyphen will
-	 *                                                 exclude posts matching that term. Eg, 'pillow -sofa' will
-	 *                                                 return posts containing 'pillow' but not 'sofa'. The
-	 *                                                 character used for exclusion can be modified using the
-	 *                                                 the 'wp_query_search_exclusion_prefix' filter.
-	 *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
-	 *     @type bool         $sentence                Whether to search by phrase. Default false.
-	 *     @type bool         $suppress_filters        Whether to suppress filters. Default false.
-	 *     @type string       $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
-	 *     @type int[]        $tag__and                An array of tag IDs (AND in).
-	 *     @type int[]        $tag__in                 An array of tag IDs (OR in).
-	 *     @type int[]        $tag__not_in             An array of tag IDs (NOT in).
-	 *     @type int          $tag_id                  Tag id or comma-separated list of IDs.
-	 *     @type string[]     $tag_slug__and           An array of tag slugs (AND in).
-	 *     @type string[]     $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
-	 *                                                 true. Note: a string of comma-separated IDs will NOT work.
-	 *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
-	 *                                                 See WP_Tax_Query->__construct().
-	 *     @type string       $title                   Post title.
-	 *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
-	 *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
-	 *     @type bool         $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
-	 *                                                 disable cache priming for term meta, so that each
-	 *                                                 get_term_meta() call will hit the database.
-	 *                                                 Defaults to the value of `$update_post_term_cache`.
-	 *     @type int          $w                       The week number of the year. Default empty. Accepts numbers 0-53.
-	 *     @type int          $year                    The four-digit year. Default empty. Accepts any four-digit year.
+	 *     @type int             $attachment_id           Attachment post ID. Used for 'attachment' post_type.
+	 *     @type int|string      $author                  Author ID, or comma-separated list of IDs.
+	 *     @type string          $author_name             User 'user_nicename'.
+	 *     @type int[]           $author__in              An array of author IDs to query from.
+	 *     @type int[]           $author__not_in          An array of author IDs not to query from.
+	 *     @type bool            $cache_results           Whether to cache post information. Default true.
+	 *     @type int|string      $cat                     Category ID or comma-separated list of IDs (this or any children).
+	 *     @type int[]           $category__and           An array of category IDs (AND in).
+	 *     @type int[]           $category__in            An array of category IDs (OR in, no children).
+	 *     @type int[]           $category__not_in        An array of category IDs (NOT in).
+	 *     @type string          $category_name           Use category slug (not name, this or any children).
+	 *     @type array|int       $comment_count           Filter results by comment count. Provide an integer to match
+	 *                                                    comment count exactly. Provide an array with integer 'value'
+	 *                                                    and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
+	 *                                                    compare against comment_count in a specific way.
+	 *     @type string          $comment_status          Comment status.
+	 *     @type int             $comments_per_page       The number of comments to return per page.
+	 *                                                    Default 'comments_per_page' option.
+	 *     @type array           $date_query              An associative array of WP_Date_Query arguments.
+	 *                                                    See WP_Date_Query::__construct().
+	 *     @type int             $day                     Day of the month. Default empty. Accepts numbers 1-31.
+	 *     @type bool            $exact                   Whether to search by exact keyword. Default false.
+	 *     @type string          $fields                  Post fields to query for. Accepts:
+	 *                                                    - '' Returns an array of complete post objects (`WP_Post[]`).
+	 *                                                    - 'ids' Returns an array of post IDs (`int[]`).
+	 *                                                    - 'id=>parent' Returns an associative array of parent post IDs,
+	 *                                                      keyed by post ID (`int[]`).
+	 *                                                    Default ''.
+	 *     @type int             $hour                    Hour of the day. Default empty. Accepts numbers 0-23.
+	 *     @type int|bool        $ignore_sticky_posts     Whether to ignore sticky posts or not. Setting this to false
+	 *                                                    excludes stickies from 'post__in'. Accepts 1|true, 0|false.
+	 *                                                    Default false.
+	 *     @type int             $m                       Combination YearMonth. Accepts any four-digit year and month
+	 *                                                    numbers 1-12. Default empty.
+	 *     @type string|string[] $meta_key                Meta key or keys to filter by.
+	 *     @type string|string[] $meta_value              Meta value or values to filter by.
+	 *     @type string          $meta_compare            MySQL operator used for comparing the meta value.
+	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
+	 *     @type string          $meta_compare_key        MySQL operator used for comparing the meta key.
+	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
+	 *     @type string          $meta_type               MySQL data type that the meta_value column will be CAST to for comparisons.
+	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
+	 *     @type string          $meta_type_key           MySQL data type that the meta_key column will be CAST to for comparisons.
+	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
+	 *     @type array           $meta_query              An associative array of WP_Meta_Query arguments.
+	 *                                                    See WP_Meta_Query::__construct for accepted values.
+	 *     @type int             $menu_order              The menu order of the posts.
+	 *     @type int             $minute                  Minute of the hour. Default empty. Accepts numbers 0-59.
+	 *     @type int             $monthnum                The two-digit month. Default empty. Accepts numbers 1-12.
+	 *     @type string          $name                    Post slug.
+	 *     @type bool            $nopaging                Show all posts (true) or paginate (false). Default false.
+	 *     @type bool            $no_found_rows           Whether to skip counting the total rows found. Enabling can improve
+	 *                                                    performance. Default false.
+	 *     @type int             $offset                  The number of posts to offset before retrieval.
+	 *     @type string          $order                   Designates ascending or descending order of posts. Default 'DESC'.
+	 *                                                    Accepts 'ASC', 'DESC'.
+	 *     @type string|array    $orderby                 Sort retrieved posts by parameter. One or more options may be passed.
+	 *                                                    To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be
+	 *                                                    also be defined. To sort by a specific `$meta_query` clause, use that
+	 *                                                    clause's array key. Accepts:
+	 *                                                    - 'none'
+	 *                                                    - 'name'
+	 *                                                    - 'author'
+	 *                                                    - 'date'
+	 *                                                    - 'title'
+	 *                                                    - 'modified'
+	 *                                                    - 'menu_order'
+	 *                                                    - 'parent'
+	 *                                                    - 'ID'
+	 *                                                    - 'rand'
+	 *                                                    - 'relevance'
+	 *                                                    - 'RAND(x)' (where 'x' is an integer seed value)
+	 *                                                    - 'comment_count'
+	 *                                                    - 'meta_value'
+	 *                                                    - 'meta_value_num'
+	 *                                                    - 'post__in'
+	 *                                                    - 'post_name__in'
+	 *                                                    - 'post_parent__in'
+	 *                                                    - The array keys of `$meta_query`.
+	 *                                                    Default is 'date', except when a search is being performed, when
+	 *                                                    the default is 'relevance'.
+	 *     @type int             $p                       Post ID.
+	 *     @type int             $page                    Show the number of posts that would show up on page X of a
+	 *                                                    static front page.
+	 *     @type int             $paged                   The number of the current page.
+	 *     @type int             $page_id                 Page ID.
+	 *     @type string          $pagename                Page slug.
+	 *     @type string          $perm                    Show posts if user has the appropriate capability.
+	 *     @type string          $ping_status             Ping status.
+	 *     @type int[]           $post__in                An array of post IDs to retrieve, sticky posts will be included.
+	 *     @type int[]           $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
+	 *                                                    separated IDs will NOT work.
+	 *     @type string          $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
+	 *     @type string[]        $post_name__in           An array of post slugs that results must match.
+	 *     @type int             $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
+	 *                                                    top-level pages.
+	 *     @type int[]           $post_parent__in         An array containing parent page IDs to query child pages from.
+	 *     @type int[]           $post_parent__not_in     An array containing parent page IDs not to query child pages from.
+	 *     @type string|string[] $post_type               A post type slug (string) or array of post type slugs.
+	 *                                                    Default 'any' if using 'tax_query'.
+	 *     @type string|string[] $post_status             A post status (string) or array of post statuses.
+	 *     @type int             $posts_per_page          The number of posts to query for. Use -1 to request all posts.
+	 *     @type int             $posts_per_archive_page  The number of posts to query for by archive page. Overrides
+	 *                                                    'posts_per_page' when is_archive(), or is_search() are true.
+	 *     @type string          $s                       Search keyword(s). Prepending a term with a hyphen will
+	 *                                                    exclude posts matching that term. Eg, 'pillow -sofa' will
+	 *                                                    return posts containing 'pillow' but not 'sofa'. The
+	 *                                                    character used for exclusion can be modified using the
+	 *                                                    the 'wp_query_search_exclusion_prefix' filter.
+	 *     @type int             $second                  Second of the minute. Default empty. Accepts numbers 0-59.
+	 *     @type bool            $sentence                Whether to search by phrase. Default false.
+	 *     @type bool            $suppress_filters        Whether to suppress filters. Default false.
+	 *     @type string          $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
+	 *     @type int[]           $tag__and                An array of tag IDs (AND in).
+	 *     @type int[]           $tag__in                 An array of tag IDs (OR in).
+	 *     @type int[]           $tag__not_in             An array of tag IDs (NOT in).
+	 *     @type int             $tag_id                  Tag id or comma-separated list of IDs.
+	 *     @type string[]        $tag_slug__and           An array of tag slugs (AND in).
+	 *     @type string[]        $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
+	 *                                                    true. Note: a string of comma-separated IDs will NOT work.
+	 *     @type array           $tax_query               An associative array of WP_Tax_Query arguments.
+	 *                                                    See WP_Tax_Query->__construct().
+	 *     @type string          $title                   Post title.
+	 *     @type bool            $update_post_meta_cache  Whether to update the post meta cache. Default true.
+	 *     @type bool            $update_post_term_cache  Whether to update the post term cache. Default true.
+	 *     @type bool            $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
+	 *                                                    disable cache priming for term meta, so that each
+	 *                                                    get_term_meta() call will hit the database.
+	 *                                                    Defaults to the value of `$update_post_term_cache`.
+	 *     @type int             $w                       The week number of the year. Default empty. Accepts numbers 0-53.
+	 *     @type int             $year                    The four-digit year. Default empty. Accepts any four-digit year.
 	 * }
 	 */
 	public function parse_query( $query = '' ) {
@@ -1727,18 +1748,18 @@
 	 * Retrieves the value of a query variable.
 	 *
 	 * @since 1.5.0
-	 * @since 3.9.0 The `$default` argument was introduced.
-	 *
-	 * @param string $query_var Query variable key.
-	 * @param mixed  $default   Optional. Value to return if the query variable is not set. Default empty string.
+	 * @since 3.9.0 The `$default_value` argument was introduced.
+	 *
+	 * @param string $query_var     Query variable key.
+	 * @param mixed  $default_value Optional. Value to return if the query variable is not set. Default empty string.
 	 * @return mixed Contents of the query variable.
 	 */
-	public function get( $query_var, $default = '' ) {
+	public function get( $query_var, $default_value = '' ) {
 		if ( isset( $this->query_vars[ $query_var ] ) ) {
 			return $this->query_vars[ $query_var ];
 		}
 
-		return $default;
+		return $default_value;
 	}
 
 	/**
@@ -2420,26 +2441,28 @@
 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] );
 		}
 
+		$skip_post_status = false;
 		if ( 'any' === $post_type ) {
 			$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
 			if ( empty( $in_search_post_types ) ) {
-				$where .= ' AND 1=0 ';
+				$post_type_where  = ' AND 1=0 ';
+				$skip_post_status = true;
 			} else {
-				$where .= " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
+				$post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
 			}
 		} elseif ( ! empty( $post_type ) && is_array( $post_type ) ) {
-			$where .= " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
+			$post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
 		} elseif ( ! empty( $post_type ) ) {
-			$where           .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
+			$post_type_where  = $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
 			$post_type_object = get_post_type_object( $post_type );
 		} elseif ( $this->is_attachment ) {
-			$where           .= " AND {$wpdb->posts}.post_type = 'attachment'";
+			$post_type_where  = " AND {$wpdb->posts}.post_type = 'attachment'";
 			$post_type_object = get_post_type_object( 'attachment' );
 		} elseif ( $this->is_page ) {
-			$where           .= " AND {$wpdb->posts}.post_type = 'page'";
+			$post_type_where  = " AND {$wpdb->posts}.post_type = 'page'";
 			$post_type_object = get_post_type_object( 'page' );
 		} else {
-			$where           .= " AND {$wpdb->posts}.post_type = 'post'";
+			$post_type_where  = " AND {$wpdb->posts}.post_type = 'post'";
 			$post_type_object = get_post_type_object( 'post' );
 		}
 
@@ -2457,7 +2480,12 @@
 		$user_id = get_current_user_id();
 
 		$q_status = array();
-		if ( ! empty( $q['post_status'] ) ) {
+		if ( $skip_post_status ) {
+			$where .= $post_type_where;
+		} elseif ( ! empty( $q['post_status'] ) ) {
+
+			$where .= $post_type_where;
+
 			$statuswheres = array();
 			$q_status     = $q['post_status'];
 			if ( ! is_array( $q_status ) ) {
@@ -2517,39 +2545,69 @@
 				$where .= " AND ($where_status)";
 			}
 		} elseif ( ! $this->is_singular ) {
-			$where .= " AND ({$wpdb->posts}.post_status = 'publish'";
-
-			// Add public states.
-			$public_states = get_post_stati( array( 'public' => true ) );
-			foreach ( (array) $public_states as $state ) {
-				if ( 'publish' === $state ) { // Publish is hard-coded above.
-					continue;
-				}
-				$where .= " OR {$wpdb->posts}.post_status = '$state'";
+			if ( 'any' === $post_type ) {
+				$queried_post_types = get_post_types( array( 'exclude_from_search' => false ) );
+			} elseif ( is_array( $post_type ) ) {
+				$queried_post_types = $post_type;
+			} elseif ( ! empty( $post_type ) ) {
+				$queried_post_types = array( $post_type );
+			} else {
+				$queried_post_types = array( 'post' );
 			}
 
-			if ( $this->is_admin ) {
-				// Add protected states that should show in the admin all list.
-				$admin_all_states = get_post_stati(
-					array(
-						'protected'              => true,
-						'show_in_admin_all_list' => true,
-					)
-				);
-				foreach ( (array) $admin_all_states as $state ) {
-					$where .= " OR {$wpdb->posts}.post_status = '$state'";
+			if ( ! empty( $queried_post_types ) ) {
+
+				$status_type_clauses = array();
+
+				foreach ( $queried_post_types as $queried_post_type ) {
+
+					$queried_post_type_object = get_post_type_object( $queried_post_type );
+
+					$type_where = '(' . $wpdb->prepare( "{$wpdb->posts}.post_type = %s AND (", $queried_post_type );
+
+					// Public statuses.
+					$public_statuses = get_post_stati( array( 'public' => true ) );
+					$status_clauses  = array();
+					foreach ( $public_statuses as $public_status ) {
+						$status_clauses[] = "{$wpdb->posts}.post_status = '$public_status'";
+					}
+					$type_where .= implode( ' OR ', $status_clauses );
+
+					// Add protected states that should show in the admin all list.
+					if ( $this->is_admin ) {
+						$admin_all_statuses = get_post_stati(
+							array(
+								'protected'              => true,
+								'show_in_admin_all_list' => true,
+							)
+						);
+						foreach ( $admin_all_statuses as $admin_all_status ) {
+							$type_where .= " OR {$wpdb->posts}.post_status = '$admin_all_status'";
+						}
+					}
+
+					// Add private states that are visible to current user.
+					if ( is_user_logged_in() && $queried_post_type_object instanceof WP_Post_Type ) {
+						$read_private_cap = $queried_post_type_object->cap->read_private_posts;
+						$private_statuses = get_post_stati( array( 'private' => true ) );
+						foreach ( $private_statuses as $private_status ) {
+							$type_where .= current_user_can( $read_private_cap ) ? " \nOR {$wpdb->posts}.post_status = '$private_status'" : " \nOR ({$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$private_status')";
+						}
+					}
+
+					$type_where .= '))';
+
+					$status_type_clauses[] = $type_where;
 				}
+
+				if ( ! empty( $status_type_clauses ) ) {
+					$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
+				}
+			} else {
+				$where .= ' AND 1=0 ';
 			}
-
-			if ( is_user_logged_in() ) {
-				// Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
-				$private_states = get_post_stati( array( 'private' => true ) );
-				foreach ( (array) $private_states as $state ) {
-					$where .= current_user_can( $read_private_cap ) ? " OR {$wpdb->posts}.post_status = '$state'" : " OR {$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$state'";
-				}
-			}
-
-			$where .= ')';
+		} else {
+			$where .= $post_type_where;
 		}
 
 		/*
@@ -2663,10 +2721,22 @@
 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
 			$climits  = ( ! empty( $climits ) ) ? $climits : '';
 
-			$comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" );
+			$comments_request = "SELECT $distinct {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
+
+			$key          = md5( $comments_request );
+			$last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );
+
+			$cache_key   = "comment_feed:$key:$last_changed";
+			$comment_ids = wp_cache_get( $cache_key, 'comment' );
+			if ( false === $comment_ids ) {
+				$comment_ids = $wpdb->get_col( $comments_request );
+				wp_cache_add( $cache_key, $comment_ids, 'comment' );
+			}
+			_prime_comment_caches( $comment_ids, false );
+
 			// Convert to WP_Comment.
 			/** @var WP_Comment[] */
-			$this->comments      = array_map( 'get_comment', $comments );
+			$this->comments      = array_map( 'get_comment', $comment_ids );
 			$this->comment_count = count( $this->comments );
 
 			$post_ids = array();
@@ -2769,11 +2839,21 @@
 			 * Filters all query clauses at once, for convenience.
 			 *
 			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
-			 * fields (SELECT), and LIMITS clauses.
+			 * fields (SELECT), and LIMIT clauses.
 			 *
 			 * @since 3.1.0
 			 *
-			 * @param string[] $clauses Associative array of the clauses for the query.
+			 * @param string[] $clauses {
+			 *     Associative array of the clauses for the query.
+			 *
+			 *     @type string $where    The WHERE clause of the query.
+			 *     @type string $groupby  The GROUP BY clause of the query.
+			 *     @type string $join     The JOIN clause of the query.
+			 *     @type string $orderby  The ORDER BY clause of the query.
+			 *     @type string $distinct The DISTINCT clause of the query.
+			 *     @type string $fields   The SELECT clause of the query.
+			 *     @type string $limits   The LIMIT clause of the query.
+			 * }
 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
 			 */
 			$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
@@ -2893,11 +2973,21 @@
 			 * For use by caching plugins.
 			 *
 			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
-			 * fields (SELECT), and LIMITS clauses.
+			 * fields (SELECT), and LIMIT clauses.
 			 *
 			 * @since 3.1.0
 			 *
-			 * @param string[] $pieces Associative array of the pieces of the query.
+			 * @param string[] $clauses {
+			 *     Associative array of the clauses for the query.
+			 *
+			 *     @type string $where    The WHERE clause of the query.
+			 *     @type string $groupby  The GROUP BY clause of the query.
+			 *     @type string $join     The JOIN clause of the query.
+			 *     @type string $orderby  The ORDER BY clause of the query.
+			 *     @type string $distinct The DISTINCT clause of the query.
+			 *     @type string $fields   The SELECT clause of the query.
+			 *     @type string $limits   The LIMIT clause of the query.
+			 * }
 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
 			 */
 			$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
@@ -2923,7 +3013,15 @@
 			$found_rows = 'SQL_CALC_FOUND_ROWS';
 		}
 
-		$old_request   = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
+		$old_request = "
+			SELECT $found_rows $distinct $fields
+			FROM {$wpdb->posts} $join
+			WHERE 1=1 $where
+			$groupby
+			$orderby
+			$limits
+		";
+
 		$this->request = $old_request;
 
 		if ( ! $q['suppress_filters'] ) {
@@ -3009,7 +3107,14 @@
 			if ( $split_the_query ) {
 				// First get the IDs and then fill in the objects.
 
-				$this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
+				$this->request = "
+					SELECT $found_rows $distinct {$wpdb->posts}.ID
+					FROM {$wpdb->posts} $join
+					WHERE 1=1 $where
+					$groupby
+					$orderby
+					$limits
+				";
 
 				/**
 				 * Filters the Post IDs SQL request before sending.
@@ -3072,11 +3177,22 @@
 			/** This filter is documented in wp-includes/query.php */
 			$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
 
-			$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
-			$comments         = $wpdb->get_results( $comments_request );
+			$comments_request = "SELECT {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
+
+			$key          = md5( $comments_request );
+			$last_changed = wp_cache_get_last_changed( 'comment' );
+
+			$cache_key   = "comment_feed:$key:$last_changed";
+			$comment_ids = wp_cache_get( $cache_key, 'comment' );
+			if ( false === $comment_ids ) {
+				$comment_ids = $wpdb->get_col( $comments_request );
+				wp_cache_add( $cache_key, $comment_ids, 'comment' );
+			}
+			_prime_comment_caches( $comment_ids, false );
+
 			// Convert to WP_Comment.
 			/** @var WP_Comment[] */
-			$this->comments      = array_map( 'get_comment', $comments );
+			$this->comments      = array_map( 'get_comment', $comment_ids );
 			$this->comment_count = count( $this->comments );
 		}
 
@@ -3168,10 +3284,15 @@
 			if ( ! empty( $sticky_posts ) ) {
 				$stickies = get_posts(
 					array(
-						'post__in'    => $sticky_posts,
-						'post_type'   => $post_type,
-						'post_status' => 'publish',
-						'nopaging'    => true,
+						'post__in'               => $sticky_posts,
+						'post_type'              => $post_type,
+						'post_status'            => 'publish',
+						'posts_per_page'         => count( $sticky_posts ),
+						'suppress_filters'       => $q['suppress_filters'],
+						'cache_results'          => $q['cache_results'],
+						'update_post_meta_cache' => $q['update_post_meta_cache'],
+						'update_post_term_cache' => $q['update_post_term_cache'],
+						'lazy_load_term_meta'    => $q['lazy_load_term_meta'],
 					)
 				);
 
@@ -3486,16 +3607,22 @@
 
 		if ( $this->is_category || $this->is_tag || $this->is_tax ) {
 			if ( $this->is_category ) {
-				if ( $this->get( 'cat' ) ) {
-					$term = get_term( $this->get( 'cat' ), 'category' );
-				} elseif ( $this->get( 'category_name' ) ) {
-					$term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' );
+				$cat           = $this->get( 'cat' );
+				$category_name = $this->get( 'category_name' );
+
+				if ( $cat ) {
+					$term = get_term( $cat, 'category' );
+				} elseif ( $category_name ) {
+					$term = get_term_by( 'slug', $category_name, 'category' );
 				}
 			} elseif ( $this->is_tag ) {
-				if ( $this->get( 'tag_id' ) ) {
-					$term = get_term( $this->get( 'tag_id' ), 'post_tag' );
-				} elseif ( $this->get( 'tag' ) ) {
-					$term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' );
+				$tag_id = $this->get( 'tag_id' );
+				$tag    = $this->get( 'tag' );
+
+				if ( $tag_id ) {
+					$term = get_term( $tag_id, 'post_tag' );
+				} elseif ( $tag ) {
+					$term = get_term_by( 'slug', $tag, 'post_tag' );
 				}
 			} else {
 				// For other tax queries, grab the first term from the first clause.
@@ -3524,20 +3651,35 @@
 			}
 		} elseif ( $this->is_post_type_archive ) {
 			$post_type = $this->get( 'post_type' );
+
 			if ( is_array( $post_type ) ) {
 				$post_type = reset( $post_type );
 			}
+
 			$this->queried_object = get_post_type_object( $post_type );
 		} elseif ( $this->is_posts_page ) {
-			$page_for_posts          = get_option( 'page_for_posts' );
+			$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 && ! empty( $this->post ) ) {
 			$this->queried_object    = $this->post;
 			$this->queried_object_id = (int) $this->post->ID;
 		} elseif ( $this->is_author ) {
-			$this->queried_object_id = (int) $this->get( 'author' );
-			$this->queried_object    = get_userdata( $this->queried_object_id );
+			$author      = (int) $this->get( 'author' );
+			$author_name = $this->get( 'author_name' );
+
+			if ( $author ) {
+				$this->queried_object_id = $author;
+			} elseif ( $author_name ) {
+				$user = get_user_by( 'slug', $author_name );
+
+				if ( $user ) {
+					$this->queried_object_id = $user->ID;
+				}
+			}
+
+			$this->queried_object = get_userdata( $this->queried_object_id );
 		}
 
 		return $this->queried_object;
@@ -3817,7 +3959,7 @@
 	 *
 	 * @since 3.1.0
 	 *
-	 * @global array $wp_taxonomies
+	 * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies.
 	 *
 	 * @param string|string[]           $taxonomy Optional. Taxonomy slug or slugs to check against.
 	 *                                            Default empty.