wp/wp-includes/class-wp-query.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    16  * @since 4.5.0 Removed the `$comments_popup` property.
    16  * @since 4.5.0 Removed the `$comments_popup` property.
    17  */
    17  */
    18 class WP_Query {
    18 class WP_Query {
    19 
    19 
    20 	/**
    20 	/**
    21 	 * Query vars set by the user
    21 	 * Query vars set by the user.
    22 	 *
    22 	 *
    23 	 * @since 1.5.0
    23 	 * @since 1.5.0
    24 	 * @var array
    24 	 * @var array
    25 	 */
    25 	 */
    26 	public $query;
    26 	public $query;
    27 
    27 
    28 	/**
    28 	/**
    29 	 * Query vars, after parsing
    29 	 * Query vars, after parsing.
    30 	 *
    30 	 *
    31 	 * @since 1.5.0
    31 	 * @since 1.5.0
    32 	 * @var array
    32 	 * @var array
    33 	 */
    33 	 */
    34 	public $query_vars = array();
    34 	public $query_vars = array();
    35 
    35 
    36 	/**
    36 	/**
    37 	 * Taxonomy query, as passed to get_tax_sql()
    37 	 * Taxonomy query, as passed to get_tax_sql().
    38 	 *
    38 	 *
    39 	 * @since 3.1.0
    39 	 * @since 3.1.0
    40 	 * @var WP_Tax_Query A taxonomy query instance.
    40 	 * @var WP_Tax_Query A taxonomy query instance.
    41 	 */
    41 	 */
    42 	public $tax_query;
    42 	public $tax_query;
    43 
    43 
    44 	/**
    44 	/**
    45 	 * Metadata query container
    45 	 * Metadata query container.
    46 	 *
    46 	 *
    47 	 * @since 3.2.0
    47 	 * @since 3.2.0
    48 	 * @var WP_Meta_Query A meta query instance.
    48 	 * @var WP_Meta_Query A meta query instance.
    49 	 */
    49 	 */
    50 	public $meta_query = false;
    50 	public $meta_query = false;
    51 
    51 
    52 	/**
    52 	/**
    53 	 * Date query container
    53 	 * Date query container.
    54 	 *
    54 	 *
    55 	 * @since 3.7.0
    55 	 * @since 3.7.0
    56 	 * @var WP_Date_Query A date query instance.
    56 	 * @var WP_Date_Query A date query instance.
    57 	 */
    57 	 */
    58 	public $date_query = false;
    58 	public $date_query = false;
    90 	 * @var WP_Post[]|int[]
    90 	 * @var WP_Post[]|int[]
    91 	 */
    91 	 */
    92 	public $posts;
    92 	public $posts;
    93 
    93 
    94 	/**
    94 	/**
    95 	 * The amount of posts for the current query.
    95 	 * The number of posts for the current query.
    96 	 *
    96 	 *
    97 	 * @since 1.5.0
    97 	 * @since 1.5.0
    98 	 * @var int
    98 	 * @var int
    99 	 */
    99 	 */
   100 	public $post_count = 0;
   100 	public $post_count = 0;
   133 	 * @var WP_Comment[]
   133 	 * @var WP_Comment[]
   134 	 */
   134 	 */
   135 	public $comments;
   135 	public $comments;
   136 
   136 
   137 	/**
   137 	/**
   138 	 * The amount of comments for the posts.
   138 	 * The number of comments for the posts.
   139 	 *
   139 	 *
   140 	 * @since 2.2.0
   140 	 * @since 2.2.0
   141 	 * @var int
   141 	 * @var int
   142 	 */
   142 	 */
   143 	public $comment_count = 0;
   143 	public $comment_count = 0;
   157 	 * @var WP_Comment
   157 	 * @var WP_Comment
   158 	 */
   158 	 */
   159 	public $comment;
   159 	public $comment;
   160 
   160 
   161 	/**
   161 	/**
   162 	 * The amount of found posts for the current query.
   162 	 * The number of found posts for the current query.
   163 	 *
   163 	 *
   164 	 * If limit clause was not used, equals $post_count.
   164 	 * If limit clause was not used, equals $post_count.
   165 	 *
   165 	 *
   166 	 * @since 2.1.0
   166 	 * @since 2.1.0
   167 	 * @var int
   167 	 * @var int
   168 	 */
   168 	 */
   169 	public $found_posts = 0;
   169 	public $found_posts = 0;
   170 
   170 
   171 	/**
   171 	/**
   172 	 * The amount of pages.
   172 	 * The number of pages.
   173 	 *
   173 	 *
   174 	 * @since 2.1.0
   174 	 * @since 2.1.0
   175 	 * @var int
   175 	 * @var int
   176 	 */
   176 	 */
   177 	public $max_num_pages = 0;
   177 	public $max_num_pages = 0;
   178 
   178 
   179 	/**
   179 	/**
   180 	 * The amount of comment pages.
   180 	 * The number of comment pages.
   181 	 *
   181 	 *
   182 	 * @since 2.7.0
   182 	 * @since 2.7.0
   183 	 * @var int
   183 	 * @var int
   184 	 */
   184 	 */
   185 	public $max_num_comment_pages = 0;
   185 	public $max_num_comment_pages = 0;
   534 	 * Fills in the query variables, which do not exist within the parameter.
   534 	 * Fills in the query variables, which do not exist within the parameter.
   535 	 *
   535 	 *
   536 	 * @since 2.1.0
   536 	 * @since 2.1.0
   537 	 * @since 4.5.0 Removed the `comments_popup` public query variable.
   537 	 * @since 4.5.0 Removed the `comments_popup` public query variable.
   538 	 *
   538 	 *
   539 	 * @param array $array Defined query variables.
   539 	 * @param array $query_vars Defined query variables.
   540 	 * @return array Complete query variables with undefined ones filled in empty.
   540 	 * @return array Complete query variables with undefined ones filled in empty.
   541 	 */
   541 	 */
   542 	public function fill_query_vars( $array ) {
   542 	public function fill_query_vars( $query_vars ) {
   543 		$keys = array(
   543 		$keys = array(
   544 			'error',
   544 			'error',
   545 			'm',
   545 			'm',
   546 			'p',
   546 			'p',
   547 			'post_parent',
   547 			'post_parent',
   578 			'menu_order',
   578 			'menu_order',
   579 			'embed',
   579 			'embed',
   580 		);
   580 		);
   581 
   581 
   582 		foreach ( $keys as $key ) {
   582 		foreach ( $keys as $key ) {
   583 			if ( ! isset( $array[ $key ] ) ) {
   583 			if ( ! isset( $query_vars[ $key ] ) ) {
   584 				$array[ $key ] = '';
   584 				$query_vars[ $key ] = '';
   585 			}
   585 			}
   586 		}
   586 		}
   587 
   587 
   588 		$array_keys = array(
   588 		$array_keys = array(
   589 			'category__in',
   589 			'category__in',
   602 			'author__in',
   602 			'author__in',
   603 			'author__not_in',
   603 			'author__not_in',
   604 		);
   604 		);
   605 
   605 
   606 		foreach ( $array_keys as $key ) {
   606 		foreach ( $array_keys as $key ) {
   607 			if ( ! isset( $array[ $key ] ) ) {
   607 			if ( ! isset( $query_vars[ $key ] ) ) {
   608 				$array[ $key ] = array();
   608 				$query_vars[ $key ] = array();
   609 			}
   609 			}
   610 		}
   610 		}
   611 		return $array;
   611 
       
   612 		return $query_vars;
   612 	}
   613 	}
   613 
   614 
   614 	/**
   615 	/**
   615 	 * Parse a query string and set query type booleans.
   616 	 * Parse a query string and set query type booleans.
   616 	 *
   617 	 *
   628 	 * @since 5.3.0 Introduced the `$meta_type_key` parameter.
   629 	 * @since 5.3.0 Introduced the `$meta_type_key` parameter.
   629 	 *
   630 	 *
   630 	 * @param string|array $query {
   631 	 * @param string|array $query {
   631 	 *     Optional. Array or string of Query parameters.
   632 	 *     Optional. Array or string of Query parameters.
   632 	 *
   633 	 *
   633 	 *     @type int          $attachment_id           Attachment post ID. Used for 'attachment' post_type.
   634 	 *     @type int             $attachment_id           Attachment post ID. Used for 'attachment' post_type.
   634 	 *     @type int|string   $author                  Author ID, or comma-separated list of IDs.
   635 	 *     @type int|string      $author                  Author ID, or comma-separated list of IDs.
   635 	 *     @type string       $author_name             User 'user_nicename'.
   636 	 *     @type string          $author_name             User 'user_nicename'.
   636 	 *     @type int[]        $author__in              An array of author IDs to query from.
   637 	 *     @type int[]           $author__in              An array of author IDs to query from.
   637 	 *     @type int[]        $author__not_in          An array of author IDs not to query from.
   638 	 *     @type int[]           $author__not_in          An array of author IDs not to query from.
   638 	 *     @type bool         $cache_results           Whether to cache post information. Default true.
   639 	 *     @type bool            $cache_results           Whether to cache post information. Default true.
   639 	 *     @type int|string   $cat                     Category ID or comma-separated list of IDs (this or any children).
   640 	 *     @type int|string      $cat                     Category ID or comma-separated list of IDs (this or any children).
   640 	 *     @type int[]        $category__and           An array of category IDs (AND in).
   641 	 *     @type int[]           $category__and           An array of category IDs (AND in).
   641 	 *     @type int[]        $category__in            An array of category IDs (OR in, no children).
   642 	 *     @type int[]           $category__in            An array of category IDs (OR in, no children).
   642 	 *     @type int[]        $category__not_in        An array of category IDs (NOT in).
   643 	 *     @type int[]           $category__not_in        An array of category IDs (NOT in).
   643 	 *     @type string       $category_name           Use category slug (not name, this or any children).
   644 	 *     @type string          $category_name           Use category slug (not name, this or any children).
   644 	 *     @type array|int    $comment_count           Filter results by comment count. Provide an integer to match
   645 	 *     @type array|int       $comment_count           Filter results by comment count. Provide an integer to match
   645 	 *                                                 comment count exactly. Provide an array with integer 'value'
   646 	 *                                                    comment count exactly. Provide an array with integer 'value'
   646 	 *                                                 and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
   647 	 *                                                    and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
   647 	 *                                                 compare against comment_count in a specific way.
   648 	 *                                                    compare against comment_count in a specific way.
   648 	 *     @type string       $comment_status          Comment status.
   649 	 *     @type string          $comment_status          Comment status.
   649 	 *     @type int          $comments_per_page       The number of comments to return per page.
   650 	 *     @type int             $comments_per_page       The number of comments to return per page.
   650 	 *                                                 Default 'comments_per_page' option.
   651 	 *                                                    Default 'comments_per_page' option.
   651 	 *     @type array        $date_query              An associative array of WP_Date_Query arguments.
   652 	 *     @type array           $date_query              An associative array of WP_Date_Query arguments.
   652 	 *                                                 See WP_Date_Query::__construct().
   653 	 *                                                    See WP_Date_Query::__construct().
   653 	 *     @type int          $day                     Day of the month. Default empty. Accepts numbers 1-31.
   654 	 *     @type int             $day                     Day of the month. Default empty. Accepts numbers 1-31.
   654 	 *     @type bool         $exact                   Whether to search by exact keyword. Default false.
   655 	 *     @type bool            $exact                   Whether to search by exact keyword. Default false.
   655 	 *     @type string       $fields                  Post fields to query for. Accepts:
   656 	 *     @type string          $fields                  Post fields to query for. Accepts:
   656 	 *                                                 - '' Returns an array of complete post objects (`WP_Post[]`).
   657 	 *                                                    - '' Returns an array of complete post objects (`WP_Post[]`).
   657 	 *                                                 - 'ids' Returns an array of post IDs (`int[]`).
   658 	 *                                                    - 'ids' Returns an array of post IDs (`int[]`).
   658 	 *                                                 - 'id=>parent' Returns an associative array of parent post IDs,
   659 	 *                                                    - 'id=>parent' Returns an associative array of parent post IDs,
   659 	 *                                                   keyed by post ID (`int[]`).
   660 	 *                                                      keyed by post ID (`int[]`).
   660 	 *                                                 Default ''.
   661 	 *                                                    Default ''.
   661 	 *     @type int          $hour                    Hour of the day. Default empty. Accepts numbers 0-23.
   662 	 *     @type int             $hour                    Hour of the day. Default empty. Accepts numbers 0-23.
   662 	 *     @type int|bool     $ignore_sticky_posts     Whether to ignore sticky posts or not. Setting this to false
   663 	 *     @type int|bool        $ignore_sticky_posts     Whether to ignore sticky posts or not. Setting this to false
   663 	 *                                                 excludes stickies from 'post__in'. Accepts 1|true, 0|false.
   664 	 *                                                    excludes stickies from 'post__in'. Accepts 1|true, 0|false.
   664 	 *                                                 Default false.
   665 	 *                                                    Default false.
   665 	 *     @type int          $m                       Combination YearMonth. Accepts any four-digit year and month
   666 	 *     @type int             $m                       Combination YearMonth. Accepts any four-digit year and month
   666 	 *                                                 numbers 1-12. Default empty.
   667 	 *                                                    numbers 1-12. Default empty.
   667 	 *     @type string       $meta_compare            Comparison operator to test the 'meta_value'.
   668 	 *     @type string|string[] $meta_key                Meta key or keys to filter by.
   668 	 *     @type string       $meta_compare_key        Comparison operator to test the 'meta_key'.
   669 	 *     @type string|string[] $meta_value              Meta value or values to filter by.
   669 	 *     @type string       $meta_key                Custom field key.
   670 	 *     @type string          $meta_compare            MySQL operator used for comparing the meta value.
   670 	 *     @type array        $meta_query              An associative array of WP_Meta_Query arguments. See WP_Meta_Query.
   671 	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
   671 	 *     @type string       $meta_value              Custom field value.
   672 	 *     @type string          $meta_compare_key        MySQL operator used for comparing the meta key.
   672 	 *     @type int          $meta_value_num          Custom field value number.
   673 	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
   673 	 *     @type string       $meta_type_key           Cast for 'meta_key'. See WP_Meta_Query::construct().
   674 	 *     @type string          $meta_type               MySQL data type that the meta_value column will be CAST to for comparisons.
   674 	 *     @type int          $menu_order              The menu order of the posts.
   675 	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
   675 	 *     @type int          $monthnum                The two-digit month. Default empty. Accepts numbers 1-12.
   676 	 *     @type string          $meta_type_key           MySQL data type that the meta_key column will be CAST to for comparisons.
   676 	 *     @type string       $name                    Post slug.
   677 	 *                                                    See WP_Meta_Query::__construct for accepted values and default value.
   677 	 *     @type bool         $nopaging                Show all posts (true) or paginate (false). Default false.
   678 	 *     @type array           $meta_query              An associative array of WP_Meta_Query arguments.
   678 	 *     @type bool         $no_found_rows           Whether to skip counting the total rows found. Enabling can improve
   679 	 *                                                    See WP_Meta_Query::__construct for accepted values.
   679 	 *                                                 performance. Default false.
   680 	 *     @type int             $menu_order              The menu order of the posts.
   680 	 *     @type int          $offset                  The number of posts to offset before retrieval.
   681 	 *     @type int             $minute                  Minute of the hour. Default empty. Accepts numbers 0-59.
   681 	 *     @type string       $order                   Designates ascending or descending order of posts. Default 'DESC'.
   682 	 *     @type int             $monthnum                The two-digit month. Default empty. Accepts numbers 1-12.
   682 	 *                                                 Accepts 'ASC', 'DESC'.
   683 	 *     @type string          $name                    Post slug.
   683 	 *     @type string|array $orderby                 Sort retrieved posts by parameter. One or more options may be
   684 	 *     @type bool            $nopaging                Show all posts (true) or paginate (false). Default false.
   684 	 *                                                 passed. To use 'meta_value', or 'meta_value_num',
   685 	 *     @type bool            $no_found_rows           Whether to skip counting the total rows found. Enabling can improve
   685 	 *                                                 'meta_key=keyname' must be also be defined. To sort by a
   686 	 *                                                    performance. Default false.
   686 	 *                                                 specific `$meta_query` clause, use that clause's array key.
   687 	 *     @type int             $offset                  The number of posts to offset before retrieval.
   687 	 *                                                 Accepts 'none', 'name', 'author', 'date', 'title',
   688 	 *     @type string          $order                   Designates ascending or descending order of posts. Default 'DESC'.
   688 	 *                                                 'modified', 'menu_order', 'parent', 'ID', 'rand',
   689 	 *                                                    Accepts 'ASC', 'DESC'.
   689 	 *                                                 'relevance', 'RAND(x)' (where 'x' is an integer seed value),
   690 	 *     @type string|array    $orderby                 Sort retrieved posts by parameter. One or more options may be passed.
   690 	 *                                                 'comment_count', 'meta_value', 'meta_value_num', 'post__in',
   691 	 *                                                    To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be
   691 	 *                                                 'post_name__in', 'post_parent__in', and the array keys
   692 	 *                                                    also be defined. To sort by a specific `$meta_query` clause, use that
   692 	 *                                                 of `$meta_query`. Default is 'date', except when a search
   693 	 *                                                    clause's array key. Accepts:
   693 	 *                                                 is being performed, when the default is 'relevance'.
   694 	 *                                                    - 'none'
   694 	 *     @type int          $p                       Post ID.
   695 	 *                                                    - 'name'
   695 	 *     @type int          $page                    Show the number of posts that would show up on page X of a
   696 	 *                                                    - 'author'
   696 	 *                                                 static front page.
   697 	 *                                                    - 'date'
   697 	 *     @type int          $paged                   The number of the current page.
   698 	 *                                                    - 'title'
   698 	 *     @type int          $page_id                 Page ID.
   699 	 *                                                    - 'modified'
   699 	 *     @type string       $pagename                Page slug.
   700 	 *                                                    - 'menu_order'
   700 	 *     @type string       $perm                    Show posts if user has the appropriate capability.
   701 	 *                                                    - 'parent'
   701 	 *     @type string       $ping_status             Ping status.
   702 	 *                                                    - 'ID'
   702 	 *     @type int[]        $post__in                An array of post IDs to retrieve, sticky posts will be included.
   703 	 *                                                    - 'rand'
   703 	 *     @type int[]        $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
   704 	 *                                                    - 'relevance'
   704 	 *                                                 separated IDs will NOT work.
   705 	 *                                                    - 'RAND(x)' (where 'x' is an integer seed value)
   705 	 *     @type string       $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
   706 	 *                                                    - 'comment_count'
   706 	 *     @type string[]     $post_name__in           An array of post slugs that results must match.
   707 	 *                                                    - 'meta_value'
   707 	 *     @type int          $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
   708 	 *                                                    - 'meta_value_num'
   708 	 *                                                 top-level pages.
   709 	 *                                                    - 'post__in'
   709 	 *     @type int[]        $post_parent__in         An array containing parent page IDs to query child pages from.
   710 	 *                                                    - 'post_name__in'
   710 	 *     @type int[]        $post_parent__not_in     An array containing parent page IDs not to query child pages from.
   711 	 *                                                    - 'post_parent__in'
   711 	 *     @type string|array $post_type               A post type slug (string) or array of post type slugs.
   712 	 *                                                    - The array keys of `$meta_query`.
   712 	 *                                                 Default 'any' if using 'tax_query'.
   713 	 *                                                    Default is 'date', except when a search is being performed, when
   713 	 *     @type string|array $post_status             A post status (string) or array of post statuses.
   714 	 *                                                    the default is 'relevance'.
   714 	 *     @type int          $posts_per_page          The number of posts to query for. Use -1 to request all posts.
   715 	 *     @type int             $p                       Post ID.
   715 	 *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
   716 	 *     @type int             $page                    Show the number of posts that would show up on page X of a
   716 	 *                                                 'posts_per_page' when is_archive(), or is_search() are true.
   717 	 *                                                    static front page.
   717 	 *     @type string       $s                       Search keyword(s). Prepending a term with a hyphen will
   718 	 *     @type int             $paged                   The number of the current page.
   718 	 *                                                 exclude posts matching that term. Eg, 'pillow -sofa' will
   719 	 *     @type int             $page_id                 Page ID.
   719 	 *                                                 return posts containing 'pillow' but not 'sofa'. The
   720 	 *     @type string          $pagename                Page slug.
   720 	 *                                                 character used for exclusion can be modified using the
   721 	 *     @type string          $perm                    Show posts if user has the appropriate capability.
   721 	 *                                                 the 'wp_query_search_exclusion_prefix' filter.
   722 	 *     @type string          $ping_status             Ping status.
   722 	 *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
   723 	 *     @type int[]           $post__in                An array of post IDs to retrieve, sticky posts will be included.
   723 	 *     @type bool         $sentence                Whether to search by phrase. Default false.
   724 	 *     @type int[]           $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
   724 	 *     @type bool         $suppress_filters        Whether to suppress filters. Default false.
   725 	 *                                                    separated IDs will NOT work.
   725 	 *     @type string       $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
   726 	 *     @type string          $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
   726 	 *     @type int[]        $tag__and                An array of tag IDs (AND in).
   727 	 *     @type string[]        $post_name__in           An array of post slugs that results must match.
   727 	 *     @type int[]        $tag__in                 An array of tag IDs (OR in).
   728 	 *     @type int             $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
   728 	 *     @type int[]        $tag__not_in             An array of tag IDs (NOT in).
   729 	 *                                                    top-level pages.
   729 	 *     @type int          $tag_id                  Tag id or comma-separated list of IDs.
   730 	 *     @type int[]           $post_parent__in         An array containing parent page IDs to query child pages from.
   730 	 *     @type string[]     $tag_slug__and           An array of tag slugs (AND in).
   731 	 *     @type int[]           $post_parent__not_in     An array containing parent page IDs not to query child pages from.
   731 	 *     @type string[]     $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
   732 	 *     @type string|string[] $post_type               A post type slug (string) or array of post type slugs.
   732 	 *                                                 true. Note: a string of comma-separated IDs will NOT work.
   733 	 *                                                    Default 'any' if using 'tax_query'.
   733 	 *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
   734 	 *     @type string|string[] $post_status             A post status (string) or array of post statuses.
   734 	 *                                                 See WP_Tax_Query->__construct().
   735 	 *     @type int             $posts_per_page          The number of posts to query for. Use -1 to request all posts.
   735 	 *     @type string       $title                   Post title.
   736 	 *     @type int             $posts_per_archive_page  The number of posts to query for by archive page. Overrides
   736 	 *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
   737 	 *                                                    'posts_per_page' when is_archive(), or is_search() are true.
   737 	 *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
   738 	 *     @type string          $s                       Search keyword(s). Prepending a term with a hyphen will
   738 	 *     @type bool         $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
   739 	 *                                                    exclude posts matching that term. Eg, 'pillow -sofa' will
   739 	 *                                                 disable cache priming for term meta, so that each
   740 	 *                                                    return posts containing 'pillow' but not 'sofa'. The
   740 	 *                                                 get_term_meta() call will hit the database.
   741 	 *                                                    character used for exclusion can be modified using the
   741 	 *                                                 Defaults to the value of `$update_post_term_cache`.
   742 	 *                                                    the 'wp_query_search_exclusion_prefix' filter.
   742 	 *     @type int          $w                       The week number of the year. Default empty. Accepts numbers 0-53.
   743 	 *     @type int             $second                  Second of the minute. Default empty. Accepts numbers 0-59.
   743 	 *     @type int          $year                    The four-digit year. Default empty. Accepts any four-digit year.
   744 	 *     @type bool            $sentence                Whether to search by phrase. Default false.
       
   745 	 *     @type bool            $suppress_filters        Whether to suppress filters. Default false.
       
   746 	 *     @type string          $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
       
   747 	 *     @type int[]           $tag__and                An array of tag IDs (AND in).
       
   748 	 *     @type int[]           $tag__in                 An array of tag IDs (OR in).
       
   749 	 *     @type int[]           $tag__not_in             An array of tag IDs (NOT in).
       
   750 	 *     @type int             $tag_id                  Tag id or comma-separated list of IDs.
       
   751 	 *     @type string[]        $tag_slug__and           An array of tag slugs (AND in).
       
   752 	 *     @type string[]        $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
       
   753 	 *                                                    true. Note: a string of comma-separated IDs will NOT work.
       
   754 	 *     @type array           $tax_query               An associative array of WP_Tax_Query arguments.
       
   755 	 *                                                    See WP_Tax_Query->__construct().
       
   756 	 *     @type string          $title                   Post title.
       
   757 	 *     @type bool            $update_post_meta_cache  Whether to update the post meta cache. Default true.
       
   758 	 *     @type bool            $update_post_term_cache  Whether to update the post term cache. Default true.
       
   759 	 *     @type bool            $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
       
   760 	 *                                                    disable cache priming for term meta, so that each
       
   761 	 *                                                    get_term_meta() call will hit the database.
       
   762 	 *                                                    Defaults to the value of `$update_post_term_cache`.
       
   763 	 *     @type int             $w                       The week number of the year. Default empty. Accepts numbers 0-53.
       
   764 	 *     @type int             $year                    The four-digit year. Default empty. Accepts any four-digit year.
   744 	 * }
   765 	 * }
   745 	 */
   766 	 */
   746 	public function parse_query( $query = '' ) {
   767 	public function parse_query( $query = '' ) {
   747 		if ( ! empty( $query ) ) {
   768 		if ( ! empty( $query ) ) {
   748 			$this->init();
   769 			$this->init();
  1725 
  1746 
  1726 	/**
  1747 	/**
  1727 	 * Retrieves the value of a query variable.
  1748 	 * Retrieves the value of a query variable.
  1728 	 *
  1749 	 *
  1729 	 * @since 1.5.0
  1750 	 * @since 1.5.0
  1730 	 * @since 3.9.0 The `$default` argument was introduced.
  1751 	 * @since 3.9.0 The `$default_value` argument was introduced.
  1731 	 *
  1752 	 *
  1732 	 * @param string $query_var Query variable key.
  1753 	 * @param string $query_var     Query variable key.
  1733 	 * @param mixed  $default   Optional. Value to return if the query variable is not set. Default empty string.
  1754 	 * @param mixed  $default_value Optional. Value to return if the query variable is not set. Default empty string.
  1734 	 * @return mixed Contents of the query variable.
  1755 	 * @return mixed Contents of the query variable.
  1735 	 */
  1756 	 */
  1736 	public function get( $query_var, $default = '' ) {
  1757 	public function get( $query_var, $default_value = '' ) {
  1737 		if ( isset( $this->query_vars[ $query_var ] ) ) {
  1758 		if ( isset( $this->query_vars[ $query_var ] ) ) {
  1738 			return $this->query_vars[ $query_var ];
  1759 			return $this->query_vars[ $query_var ];
  1739 		}
  1760 		}
  1740 
  1761 
  1741 		return $default;
  1762 		return $default_value;
  1742 	}
  1763 	}
  1743 
  1764 
  1744 	/**
  1765 	/**
  1745 	 * Sets the value of a query variable.
  1766 	 * Sets the value of a query variable.
  1746 	 *
  1767 	 *
  2418 
  2439 
  2419 		if ( ! empty( $q['ping_status'] ) ) {
  2440 		if ( ! empty( $q['ping_status'] ) ) {
  2420 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] );
  2441 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] );
  2421 		}
  2442 		}
  2422 
  2443 
       
  2444 		$skip_post_status = false;
  2423 		if ( 'any' === $post_type ) {
  2445 		if ( 'any' === $post_type ) {
  2424 			$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
  2446 			$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
  2425 			if ( empty( $in_search_post_types ) ) {
  2447 			if ( empty( $in_search_post_types ) ) {
  2426 				$where .= ' AND 1=0 ';
  2448 				$post_type_where  = ' AND 1=0 ';
       
  2449 				$skip_post_status = true;
  2427 			} else {
  2450 			} else {
  2428 				$where .= " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
  2451 				$post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
  2429 			}
  2452 			}
  2430 		} elseif ( ! empty( $post_type ) && is_array( $post_type ) ) {
  2453 		} elseif ( ! empty( $post_type ) && is_array( $post_type ) ) {
  2431 			$where .= " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
  2454 			$post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
  2432 		} elseif ( ! empty( $post_type ) ) {
  2455 		} elseif ( ! empty( $post_type ) ) {
  2433 			$where           .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
  2456 			$post_type_where  = $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
  2434 			$post_type_object = get_post_type_object( $post_type );
  2457 			$post_type_object = get_post_type_object( $post_type );
  2435 		} elseif ( $this->is_attachment ) {
  2458 		} elseif ( $this->is_attachment ) {
  2436 			$where           .= " AND {$wpdb->posts}.post_type = 'attachment'";
  2459 			$post_type_where  = " AND {$wpdb->posts}.post_type = 'attachment'";
  2437 			$post_type_object = get_post_type_object( 'attachment' );
  2460 			$post_type_object = get_post_type_object( 'attachment' );
  2438 		} elseif ( $this->is_page ) {
  2461 		} elseif ( $this->is_page ) {
  2439 			$where           .= " AND {$wpdb->posts}.post_type = 'page'";
  2462 			$post_type_where  = " AND {$wpdb->posts}.post_type = 'page'";
  2440 			$post_type_object = get_post_type_object( 'page' );
  2463 			$post_type_object = get_post_type_object( 'page' );
  2441 		} else {
  2464 		} else {
  2442 			$where           .= " AND {$wpdb->posts}.post_type = 'post'";
  2465 			$post_type_where  = " AND {$wpdb->posts}.post_type = 'post'";
  2443 			$post_type_object = get_post_type_object( 'post' );
  2466 			$post_type_object = get_post_type_object( 'post' );
  2444 		}
  2467 		}
  2445 
  2468 
  2446 		$edit_cap = 'edit_post';
  2469 		$edit_cap = 'edit_post';
  2447 		$read_cap = 'read_post';
  2470 		$read_cap = 'read_post';
  2455 		}
  2478 		}
  2456 
  2479 
  2457 		$user_id = get_current_user_id();
  2480 		$user_id = get_current_user_id();
  2458 
  2481 
  2459 		$q_status = array();
  2482 		$q_status = array();
  2460 		if ( ! empty( $q['post_status'] ) ) {
  2483 		if ( $skip_post_status ) {
       
  2484 			$where .= $post_type_where;
       
  2485 		} elseif ( ! empty( $q['post_status'] ) ) {
       
  2486 
       
  2487 			$where .= $post_type_where;
       
  2488 
  2461 			$statuswheres = array();
  2489 			$statuswheres = array();
  2462 			$q_status     = $q['post_status'];
  2490 			$q_status     = $q['post_status'];
  2463 			if ( ! is_array( $q_status ) ) {
  2491 			if ( ! is_array( $q_status ) ) {
  2464 				$q_status = explode( ',', $q_status );
  2492 				$q_status = explode( ',', $q_status );
  2465 			}
  2493 			}
  2515 			$where_status = implode( ' OR ', $statuswheres );
  2543 			$where_status = implode( ' OR ', $statuswheres );
  2516 			if ( ! empty( $where_status ) ) {
  2544 			if ( ! empty( $where_status ) ) {
  2517 				$where .= " AND ($where_status)";
  2545 				$where .= " AND ($where_status)";
  2518 			}
  2546 			}
  2519 		} elseif ( ! $this->is_singular ) {
  2547 		} elseif ( ! $this->is_singular ) {
  2520 			$where .= " AND ({$wpdb->posts}.post_status = 'publish'";
  2548 			if ( 'any' === $post_type ) {
  2521 
  2549 				$queried_post_types = get_post_types( array( 'exclude_from_search' => false ) );
  2522 			// Add public states.
  2550 			} elseif ( is_array( $post_type ) ) {
  2523 			$public_states = get_post_stati( array( 'public' => true ) );
  2551 				$queried_post_types = $post_type;
  2524 			foreach ( (array) $public_states as $state ) {
  2552 			} elseif ( ! empty( $post_type ) ) {
  2525 				if ( 'publish' === $state ) { // Publish is hard-coded above.
  2553 				$queried_post_types = array( $post_type );
  2526 					continue;
  2554 			} else {
  2527 				}
  2555 				$queried_post_types = array( 'post' );
  2528 				$where .= " OR {$wpdb->posts}.post_status = '$state'";
  2556 			}
  2529 			}
  2557 
  2530 
  2558 			if ( ! empty( $queried_post_types ) ) {
  2531 			if ( $this->is_admin ) {
  2559 
  2532 				// Add protected states that should show in the admin all list.
  2560 				$status_type_clauses = array();
  2533 				$admin_all_states = get_post_stati(
  2561 
  2534 					array(
  2562 				foreach ( $queried_post_types as $queried_post_type ) {
  2535 						'protected'              => true,
  2563 
  2536 						'show_in_admin_all_list' => true,
  2564 					$queried_post_type_object = get_post_type_object( $queried_post_type );
  2537 					)
  2565 
  2538 				);
  2566 					$type_where = '(' . $wpdb->prepare( "{$wpdb->posts}.post_type = %s AND (", $queried_post_type );
  2539 				foreach ( (array) $admin_all_states as $state ) {
  2567 
  2540 					$where .= " OR {$wpdb->posts}.post_status = '$state'";
  2568 					// Public statuses.
  2541 				}
  2569 					$public_statuses = get_post_stati( array( 'public' => true ) );
  2542 			}
  2570 					$status_clauses  = array();
  2543 
  2571 					foreach ( $public_statuses as $public_status ) {
  2544 			if ( is_user_logged_in() ) {
  2572 						$status_clauses[] = "{$wpdb->posts}.post_status = '$public_status'";
  2545 				// Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
  2573 					}
  2546 				$private_states = get_post_stati( array( 'private' => true ) );
  2574 					$type_where .= implode( ' OR ', $status_clauses );
  2547 				foreach ( (array) $private_states as $state ) {
  2575 
  2548 					$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'";
  2576 					// Add protected states that should show in the admin all list.
  2549 				}
  2577 					if ( $this->is_admin ) {
  2550 			}
  2578 						$admin_all_statuses = get_post_stati(
  2551 
  2579 							array(
  2552 			$where .= ')';
  2580 								'protected'              => true,
       
  2581 								'show_in_admin_all_list' => true,
       
  2582 							)
       
  2583 						);
       
  2584 						foreach ( $admin_all_statuses as $admin_all_status ) {
       
  2585 							$type_where .= " OR {$wpdb->posts}.post_status = '$admin_all_status'";
       
  2586 						}
       
  2587 					}
       
  2588 
       
  2589 					// Add private states that are visible to current user.
       
  2590 					if ( is_user_logged_in() && $queried_post_type_object instanceof WP_Post_Type ) {
       
  2591 						$read_private_cap = $queried_post_type_object->cap->read_private_posts;
       
  2592 						$private_statuses = get_post_stati( array( 'private' => true ) );
       
  2593 						foreach ( $private_statuses as $private_status ) {
       
  2594 							$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')";
       
  2595 						}
       
  2596 					}
       
  2597 
       
  2598 					$type_where .= '))';
       
  2599 
       
  2600 					$status_type_clauses[] = $type_where;
       
  2601 				}
       
  2602 
       
  2603 				if ( ! empty( $status_type_clauses ) ) {
       
  2604 					$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
       
  2605 				}
       
  2606 			} else {
       
  2607 				$where .= ' AND 1=0 ';
       
  2608 			}
       
  2609 		} else {
       
  2610 			$where .= $post_type_where;
  2553 		}
  2611 		}
  2554 
  2612 
  2555 		/*
  2613 		/*
  2556 		 * Apply filters on where and join prior to paging so that any
  2614 		 * Apply filters on where and join prior to paging so that any
  2557 		 * manipulations to them are reflected in the paging by day queries.
  2615 		 * manipulations to them are reflected in the paging by day queries.
  2661 
  2719 
  2662 			$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
  2720 			$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
  2663 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
  2721 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
  2664 			$climits  = ( ! empty( $climits ) ) ? $climits : '';
  2722 			$climits  = ( ! empty( $climits ) ) ? $climits : '';
  2665 
  2723 
  2666 			$comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" );
  2724 			$comments_request = "SELECT $distinct {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
       
  2725 
       
  2726 			$key          = md5( $comments_request );
       
  2727 			$last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );
       
  2728 
       
  2729 			$cache_key   = "comment_feed:$key:$last_changed";
       
  2730 			$comment_ids = wp_cache_get( $cache_key, 'comment' );
       
  2731 			if ( false === $comment_ids ) {
       
  2732 				$comment_ids = $wpdb->get_col( $comments_request );
       
  2733 				wp_cache_add( $cache_key, $comment_ids, 'comment' );
       
  2734 			}
       
  2735 			_prime_comment_caches( $comment_ids, false );
       
  2736 
  2667 			// Convert to WP_Comment.
  2737 			// Convert to WP_Comment.
  2668 			/** @var WP_Comment[] */
  2738 			/** @var WP_Comment[] */
  2669 			$this->comments      = array_map( 'get_comment', $comments );
  2739 			$this->comments      = array_map( 'get_comment', $comment_ids );
  2670 			$this->comment_count = count( $this->comments );
  2740 			$this->comment_count = count( $this->comments );
  2671 
  2741 
  2672 			$post_ids = array();
  2742 			$post_ids = array();
  2673 
  2743 
  2674 			foreach ( $this->comments as $comment ) {
  2744 			foreach ( $this->comments as $comment ) {
  2767 
  2837 
  2768 			/**
  2838 			/**
  2769 			 * Filters all query clauses at once, for convenience.
  2839 			 * Filters all query clauses at once, for convenience.
  2770 			 *
  2840 			 *
  2771 			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
  2841 			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
  2772 			 * fields (SELECT), and LIMITS clauses.
  2842 			 * fields (SELECT), and LIMIT clauses.
  2773 			 *
  2843 			 *
  2774 			 * @since 3.1.0
  2844 			 * @since 3.1.0
  2775 			 *
  2845 			 *
  2776 			 * @param string[] $clauses Associative array of the clauses for the query.
  2846 			 * @param string[] $clauses {
       
  2847 			 *     Associative array of the clauses for the query.
       
  2848 			 *
       
  2849 			 *     @type string $where    The WHERE clause of the query.
       
  2850 			 *     @type string $groupby  The GROUP BY clause of the query.
       
  2851 			 *     @type string $join     The JOIN clause of the query.
       
  2852 			 *     @type string $orderby  The ORDER BY clause of the query.
       
  2853 			 *     @type string $distinct The DISTINCT clause of the query.
       
  2854 			 *     @type string $fields   The SELECT clause of the query.
       
  2855 			 *     @type string $limits   The LIMIT clause of the query.
       
  2856 			 * }
  2777 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2857 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2778 			 */
  2858 			 */
  2779 			$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
  2859 			$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
  2780 
  2860 
  2781 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2861 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2891 			 * Filters all query clauses at once, for convenience.
  2971 			 * Filters all query clauses at once, for convenience.
  2892 			 *
  2972 			 *
  2893 			 * For use by caching plugins.
  2973 			 * For use by caching plugins.
  2894 			 *
  2974 			 *
  2895 			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
  2975 			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
  2896 			 * fields (SELECT), and LIMITS clauses.
  2976 			 * fields (SELECT), and LIMIT clauses.
  2897 			 *
  2977 			 *
  2898 			 * @since 3.1.0
  2978 			 * @since 3.1.0
  2899 			 *
  2979 			 *
  2900 			 * @param string[] $pieces Associative array of the pieces of the query.
  2980 			 * @param string[] $clauses {
       
  2981 			 *     Associative array of the clauses for the query.
       
  2982 			 *
       
  2983 			 *     @type string $where    The WHERE clause of the query.
       
  2984 			 *     @type string $groupby  The GROUP BY clause of the query.
       
  2985 			 *     @type string $join     The JOIN clause of the query.
       
  2986 			 *     @type string $orderby  The ORDER BY clause of the query.
       
  2987 			 *     @type string $distinct The DISTINCT clause of the query.
       
  2988 			 *     @type string $fields   The SELECT clause of the query.
       
  2989 			 *     @type string $limits   The LIMIT clause of the query.
       
  2990 			 * }
  2901 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2991 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2902 			 */
  2992 			 */
  2903 			$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
  2993 			$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
  2904 
  2994 
  2905 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2995 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2921 		$found_rows = '';
  3011 		$found_rows = '';
  2922 		if ( ! $q['no_found_rows'] && ! empty( $limits ) ) {
  3012 		if ( ! $q['no_found_rows'] && ! empty( $limits ) ) {
  2923 			$found_rows = 'SQL_CALC_FOUND_ROWS';
  3013 			$found_rows = 'SQL_CALC_FOUND_ROWS';
  2924 		}
  3014 		}
  2925 
  3015 
  2926 		$old_request   = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
  3016 		$old_request = "
       
  3017 			SELECT $found_rows $distinct $fields
       
  3018 			FROM {$wpdb->posts} $join
       
  3019 			WHERE 1=1 $where
       
  3020 			$groupby
       
  3021 			$orderby
       
  3022 			$limits
       
  3023 		";
       
  3024 
  2927 		$this->request = $old_request;
  3025 		$this->request = $old_request;
  2928 
  3026 
  2929 		if ( ! $q['suppress_filters'] ) {
  3027 		if ( ! $q['suppress_filters'] ) {
  2930 			/**
  3028 			/**
  2931 			 * Filters the completed SQL query before sending.
  3029 			 * Filters the completed SQL query before sending.
  3007 			$split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
  3105 			$split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
  3008 
  3106 
  3009 			if ( $split_the_query ) {
  3107 			if ( $split_the_query ) {
  3010 				// First get the IDs and then fill in the objects.
  3108 				// First get the IDs and then fill in the objects.
  3011 
  3109 
  3012 				$this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
  3110 				$this->request = "
       
  3111 					SELECT $found_rows $distinct {$wpdb->posts}.ID
       
  3112 					FROM {$wpdb->posts} $join
       
  3113 					WHERE 1=1 $where
       
  3114 					$groupby
       
  3115 					$orderby
       
  3116 					$limits
       
  3117 				";
  3013 
  3118 
  3014 				/**
  3119 				/**
  3015 				 * Filters the Post IDs SQL request before sending.
  3120 				 * Filters the Post IDs SQL request before sending.
  3016 				 *
  3121 				 *
  3017 				 * @since 3.4.0
  3122 				 * @since 3.4.0
  3070 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
  3175 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
  3071 
  3176 
  3072 			/** This filter is documented in wp-includes/query.php */
  3177 			/** This filter is documented in wp-includes/query.php */
  3073 			$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
  3178 			$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
  3074 
  3179 
  3075 			$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
  3180 			$comments_request = "SELECT {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
  3076 			$comments         = $wpdb->get_results( $comments_request );
  3181 
       
  3182 			$key          = md5( $comments_request );
       
  3183 			$last_changed = wp_cache_get_last_changed( 'comment' );
       
  3184 
       
  3185 			$cache_key   = "comment_feed:$key:$last_changed";
       
  3186 			$comment_ids = wp_cache_get( $cache_key, 'comment' );
       
  3187 			if ( false === $comment_ids ) {
       
  3188 				$comment_ids = $wpdb->get_col( $comments_request );
       
  3189 				wp_cache_add( $cache_key, $comment_ids, 'comment' );
       
  3190 			}
       
  3191 			_prime_comment_caches( $comment_ids, false );
       
  3192 
  3077 			// Convert to WP_Comment.
  3193 			// Convert to WP_Comment.
  3078 			/** @var WP_Comment[] */
  3194 			/** @var WP_Comment[] */
  3079 			$this->comments      = array_map( 'get_comment', $comments );
  3195 			$this->comments      = array_map( 'get_comment', $comment_ids );
  3080 			$this->comment_count = count( $this->comments );
  3196 			$this->comment_count = count( $this->comments );
  3081 		}
  3197 		}
  3082 
  3198 
  3083 		// Check post status to determine if post should be displayed.
  3199 		// Check post status to determine if post should be displayed.
  3084 		if ( ! empty( $this->posts ) && ( $this->is_single || $this->is_page ) ) {
  3200 		if ( ! empty( $this->posts ) && ( $this->is_single || $this->is_page ) ) {
  3166 
  3282 
  3167 			// Fetch sticky posts that weren't in the query results.
  3283 			// Fetch sticky posts that weren't in the query results.
  3168 			if ( ! empty( $sticky_posts ) ) {
  3284 			if ( ! empty( $sticky_posts ) ) {
  3169 				$stickies = get_posts(
  3285 				$stickies = get_posts(
  3170 					array(
  3286 					array(
  3171 						'post__in'    => $sticky_posts,
  3287 						'post__in'               => $sticky_posts,
  3172 						'post_type'   => $post_type,
  3288 						'post_type'              => $post_type,
  3173 						'post_status' => 'publish',
  3289 						'post_status'            => 'publish',
  3174 						'nopaging'    => true,
  3290 						'posts_per_page'         => count( $sticky_posts ),
       
  3291 						'suppress_filters'       => $q['suppress_filters'],
       
  3292 						'cache_results'          => $q['cache_results'],
       
  3293 						'update_post_meta_cache' => $q['update_post_meta_cache'],
       
  3294 						'update_post_term_cache' => $q['update_post_term_cache'],
       
  3295 						'lazy_load_term_meta'    => $q['lazy_load_term_meta'],
  3175 					)
  3296 					)
  3176 				);
  3297 				);
  3177 
  3298 
  3178 				foreach ( $stickies as $sticky_post ) {
  3299 				foreach ( $stickies as $sticky_post ) {
  3179 					array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
  3300 					array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
  3484 		$this->queried_object    = null;
  3605 		$this->queried_object    = null;
  3485 		$this->queried_object_id = null;
  3606 		$this->queried_object_id = null;
  3486 
  3607 
  3487 		if ( $this->is_category || $this->is_tag || $this->is_tax ) {
  3608 		if ( $this->is_category || $this->is_tag || $this->is_tax ) {
  3488 			if ( $this->is_category ) {
  3609 			if ( $this->is_category ) {
  3489 				if ( $this->get( 'cat' ) ) {
  3610 				$cat           = $this->get( 'cat' );
  3490 					$term = get_term( $this->get( 'cat' ), 'category' );
  3611 				$category_name = $this->get( 'category_name' );
  3491 				} elseif ( $this->get( 'category_name' ) ) {
  3612 
  3492 					$term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' );
  3613 				if ( $cat ) {
       
  3614 					$term = get_term( $cat, 'category' );
       
  3615 				} elseif ( $category_name ) {
       
  3616 					$term = get_term_by( 'slug', $category_name, 'category' );
  3493 				}
  3617 				}
  3494 			} elseif ( $this->is_tag ) {
  3618 			} elseif ( $this->is_tag ) {
  3495 				if ( $this->get( 'tag_id' ) ) {
  3619 				$tag_id = $this->get( 'tag_id' );
  3496 					$term = get_term( $this->get( 'tag_id' ), 'post_tag' );
  3620 				$tag    = $this->get( 'tag' );
  3497 				} elseif ( $this->get( 'tag' ) ) {
  3621 
  3498 					$term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' );
  3622 				if ( $tag_id ) {
       
  3623 					$term = get_term( $tag_id, 'post_tag' );
       
  3624 				} elseif ( $tag ) {
       
  3625 					$term = get_term_by( 'slug', $tag, 'post_tag' );
  3499 				}
  3626 				}
  3500 			} else {
  3627 			} else {
  3501 				// For other tax queries, grab the first term from the first clause.
  3628 				// For other tax queries, grab the first term from the first clause.
  3502 				if ( ! empty( $this->tax_query->queried_terms ) ) {
  3629 				if ( ! empty( $this->tax_query->queried_terms ) ) {
  3503 					$queried_taxonomies = array_keys( $this->tax_query->queried_terms );
  3630 					$queried_taxonomies = array_keys( $this->tax_query->queried_terms );
  3522 					_make_cat_compat( $this->queried_object );
  3649 					_make_cat_compat( $this->queried_object );
  3523 				}
  3650 				}
  3524 			}
  3651 			}
  3525 		} elseif ( $this->is_post_type_archive ) {
  3652 		} elseif ( $this->is_post_type_archive ) {
  3526 			$post_type = $this->get( 'post_type' );
  3653 			$post_type = $this->get( 'post_type' );
       
  3654 
  3527 			if ( is_array( $post_type ) ) {
  3655 			if ( is_array( $post_type ) ) {
  3528 				$post_type = reset( $post_type );
  3656 				$post_type = reset( $post_type );
  3529 			}
  3657 			}
       
  3658 
  3530 			$this->queried_object = get_post_type_object( $post_type );
  3659 			$this->queried_object = get_post_type_object( $post_type );
  3531 		} elseif ( $this->is_posts_page ) {
  3660 		} elseif ( $this->is_posts_page ) {
  3532 			$page_for_posts          = get_option( 'page_for_posts' );
  3661 			$page_for_posts = get_option( 'page_for_posts' );
       
  3662 
  3533 			$this->queried_object    = get_post( $page_for_posts );
  3663 			$this->queried_object    = get_post( $page_for_posts );
  3534 			$this->queried_object_id = (int) $this->queried_object->ID;
  3664 			$this->queried_object_id = (int) $this->queried_object->ID;
  3535 		} elseif ( $this->is_singular && ! empty( $this->post ) ) {
  3665 		} elseif ( $this->is_singular && ! empty( $this->post ) ) {
  3536 			$this->queried_object    = $this->post;
  3666 			$this->queried_object    = $this->post;
  3537 			$this->queried_object_id = (int) $this->post->ID;
  3667 			$this->queried_object_id = (int) $this->post->ID;
  3538 		} elseif ( $this->is_author ) {
  3668 		} elseif ( $this->is_author ) {
  3539 			$this->queried_object_id = (int) $this->get( 'author' );
  3669 			$author      = (int) $this->get( 'author' );
  3540 			$this->queried_object    = get_userdata( $this->queried_object_id );
  3670 			$author_name = $this->get( 'author_name' );
       
  3671 
       
  3672 			if ( $author ) {
       
  3673 				$this->queried_object_id = $author;
       
  3674 			} elseif ( $author_name ) {
       
  3675 				$user = get_user_by( 'slug', $author_name );
       
  3676 
       
  3677 				if ( $user ) {
       
  3678 					$this->queried_object_id = $user->ID;
       
  3679 				}
       
  3680 			}
       
  3681 
       
  3682 			$this->queried_object = get_userdata( $this->queried_object_id );
  3541 		}
  3683 		}
  3542 
  3684 
  3543 		return $this->queried_object;
  3685 		return $this->queried_object;
  3544 	}
  3686 	}
  3545 
  3687 
  3815 	 * this function will additionally check if the query is for one of the terms
  3957 	 * this function will additionally check if the query is for one of the terms
  3816 	 * specified.
  3958 	 * specified.
  3817 	 *
  3959 	 *
  3818 	 * @since 3.1.0
  3960 	 * @since 3.1.0
  3819 	 *
  3961 	 *
  3820 	 * @global array $wp_taxonomies
  3962 	 * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies.
  3821 	 *
  3963 	 *
  3822 	 * @param string|string[]           $taxonomy Optional. Taxonomy slug or slugs to check against.
  3964 	 * @param string|string[]           $taxonomy Optional. Taxonomy slug or slugs to check against.
  3823 	 *                                            Default empty.
  3965 	 *                                            Default empty.
  3824 	 * @param int|string|int[]|string[] $term     Optional. Term ID, name, slug, or array of such
  3966 	 * @param int|string|int[]|string[] $term     Optional. Term ID, name, slug, or array of such
  3825 	 *                                            to check against. Default empty.
  3967 	 *                                            to check against. Default empty.