wp/wp-includes/class-wp-query.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    61 	 * Holds the data for a single object that is queried.
    61 	 * Holds the data for a single object that is queried.
    62 	 *
    62 	 *
    63 	 * Holds the contents of a post, page, category, attachment.
    63 	 * Holds the contents of a post, page, category, attachment.
    64 	 *
    64 	 *
    65 	 * @since 1.5.0
    65 	 * @since 1.5.0
    66 	 * @var object|array
    66 	 * @var WP_Term|WP_Post_Type|WP_Post|WP_User|null
    67 	 */
    67 	 */
    68 	public $queried_object;
    68 	public $queried_object;
    69 
    69 
    70 	/**
    70 	/**
    71 	 * The ID of the queried object.
    71 	 * The ID of the queried object.
    74 	 * @var int
    74 	 * @var int
    75 	 */
    75 	 */
    76 	public $queried_object_id;
    76 	public $queried_object_id;
    77 
    77 
    78 	/**
    78 	/**
    79 	 * Get post database query.
    79 	 * SQL for the database query.
    80 	 *
    80 	 *
    81 	 * @since 2.0.1
    81 	 * @since 2.0.1
    82 	 * @var string
    82 	 * @var string
    83 	 */
    83 	 */
    84 	public $request;
    84 	public $request;
    85 
    85 
    86 	/**
    86 	/**
    87 	 * List of posts.
    87 	 * Array of post objects or post IDs.
    88 	 *
    88 	 *
    89 	 * @since 1.5.0
    89 	 * @since 1.5.0
    90 	 * @var array
    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 amount of posts for the current query.
   116 	public $in_the_loop = false;
   116 	public $in_the_loop = false;
   117 
   117 
   118 	/**
   118 	/**
   119 	 * The current post.
   119 	 * The current post.
   120 	 *
   120 	 *
       
   121 	 * This property does not get populated when the `fields` argument is set to
       
   122 	 * `ids` or `id=>parent`.
       
   123 	 *
   121 	 * @since 1.5.0
   124 	 * @since 1.5.0
   122 	 * @var WP_Post
   125 	 * @var WP_Post|null
   123 	 */
   126 	 */
   124 	public $post;
   127 	public $post;
   125 
   128 
   126 	/**
   129 	/**
   127 	 * The list of comments for current post.
   130 	 * The list of comments for current post.
   128 	 *
   131 	 *
   129 	 * @since 2.2.0
   132 	 * @since 2.2.0
   130 	 * @var array
   133 	 * @var WP_Comment[]
   131 	 */
   134 	 */
   132 	public $comments;
   135 	public $comments;
   133 
   136 
   134 	/**
   137 	/**
   135 	 * The amount of comments for the posts.
   138 	 * The amount of comments for the posts.
   146 	 * @var int
   149 	 * @var int
   147 	 */
   150 	 */
   148 	public $current_comment = -1;
   151 	public $current_comment = -1;
   149 
   152 
   150 	/**
   153 	/**
   151 	 * Current comment ID.
   154 	 * Current comment object.
   152 	 *
   155 	 *
   153 	 * @since 2.2.0
   156 	 * @since 2.2.0
   154 	 * @var int
   157 	 * @var WP_Comment
   155 	 */
   158 	 */
   156 	public $comment;
   159 	public $comment;
   157 
   160 
   158 	/**
   161 	/**
   159 	 * The amount of found posts for the current query.
   162 	 * The amount of found posts for the current query.
   628 	 *     Optional. Array or string of Query parameters.
   631 	 *     Optional. Array or string of Query parameters.
   629 	 *
   632 	 *
   630 	 *     @type int          $attachment_id           Attachment post ID. Used for 'attachment' post_type.
   633 	 *     @type int          $attachment_id           Attachment post ID. Used for 'attachment' post_type.
   631 	 *     @type int|string   $author                  Author ID, or comma-separated list of IDs.
   634 	 *     @type int|string   $author                  Author ID, or comma-separated list of IDs.
   632 	 *     @type string       $author_name             User 'user_nicename'.
   635 	 *     @type string       $author_name             User 'user_nicename'.
   633 	 *     @type array        $author__in              An array of author IDs to query from.
   636 	 *     @type int[]        $author__in              An array of author IDs to query from.
   634 	 *     @type array        $author__not_in          An array of author IDs not to query from.
   637 	 *     @type int[]        $author__not_in          An array of author IDs not to query from.
   635 	 *     @type bool         $cache_results           Whether to cache post information. Default true.
   638 	 *     @type bool         $cache_results           Whether to cache post information. Default true.
   636 	 *     @type int|string   $cat                     Category ID or comma-separated list of IDs (this or any children).
   639 	 *     @type int|string   $cat                     Category ID or comma-separated list of IDs (this or any children).
   637 	 *     @type array        $category__and           An array of category IDs (AND in).
   640 	 *     @type int[]        $category__and           An array of category IDs (AND in).
   638 	 *     @type array        $category__in            An array of category IDs (OR in, no children).
   641 	 *     @type int[]        $category__in            An array of category IDs (OR in, no children).
   639 	 *     @type array        $category__not_in        An array of category IDs (NOT in).
   642 	 *     @type int[]        $category__not_in        An array of category IDs (NOT in).
   640 	 *     @type string       $category_name           Use category slug (not name, this or any children).
   643 	 *     @type string       $category_name           Use category slug (not name, this or any children).
   641 	 *     @type array|int    $comment_count           Filter results by comment count. Provide an integer to match
   644 	 *     @type array|int    $comment_count           Filter results by comment count. Provide an integer to match
   642 	 *                                                 comment count exactly. Provide an array with integer 'value'
   645 	 *                                                 comment count exactly. Provide an array with integer 'value'
   643 	 *                                                 and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
   646 	 *                                                 and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
   644 	 *                                                 compare against comment_count in a specific way.
   647 	 *                                                 compare against comment_count in a specific way.
   694 	 *     @type int          $paged                   The number of the current page.
   697 	 *     @type int          $paged                   The number of the current page.
   695 	 *     @type int          $page_id                 Page ID.
   698 	 *     @type int          $page_id                 Page ID.
   696 	 *     @type string       $pagename                Page slug.
   699 	 *     @type string       $pagename                Page slug.
   697 	 *     @type string       $perm                    Show posts if user has the appropriate capability.
   700 	 *     @type string       $perm                    Show posts if user has the appropriate capability.
   698 	 *     @type string       $ping_status             Ping status.
   701 	 *     @type string       $ping_status             Ping status.
   699 	 *     @type array        $post__in                An array of post IDs to retrieve, sticky posts will be included.
   702 	 *     @type int[]        $post__in                An array of post IDs to retrieve, sticky posts will be included.
   700 	 *     @type array        $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
   703 	 *     @type int[]        $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
   701 	 *                                                 separated IDs will NOT work.
   704 	 *                                                 separated IDs will NOT work.
   702 	 *     @type string       $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
   705 	 *     @type string       $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
   703 	 *     @type array        $post_name__in           An array of post slugs that results must match.
   706 	 *     @type string[]     $post_name__in           An array of post slugs that results must match.
   704 	 *     @type int          $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
   707 	 *     @type int          $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
   705 	 *                                                 top-level pages.
   708 	 *                                                 top-level pages.
   706 	 *     @type array        $post_parent__in         An array containing parent page IDs to query child pages from.
   709 	 *     @type int[]        $post_parent__in         An array containing parent page IDs to query child pages from.
   707 	 *     @type array        $post_parent__not_in     An array containing parent page IDs not to query child pages from.
   710 	 *     @type int[]        $post_parent__not_in     An array containing parent page IDs not to query child pages from.
   708 	 *     @type string|array $post_type               A post type slug (string) or array of post type slugs.
   711 	 *     @type string|array $post_type               A post type slug (string) or array of post type slugs.
   709 	 *                                                 Default 'any' if using 'tax_query'.
   712 	 *                                                 Default 'any' if using 'tax_query'.
   710 	 *     @type string|array $post_status             A post status (string) or array of post statuses.
   713 	 *     @type string|array $post_status             A post status (string) or array of post statuses.
   711 	 *     @type int          $posts_per_page          The number of posts to query for. Use -1 to request all posts.
   714 	 *     @type int          $posts_per_page          The number of posts to query for. Use -1 to request all posts.
   712 	 *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
   715 	 *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
   718 	 *                                                 the 'wp_query_search_exclusion_prefix' filter.
   721 	 *                                                 the 'wp_query_search_exclusion_prefix' filter.
   719 	 *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
   722 	 *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
   720 	 *     @type bool         $sentence                Whether to search by phrase. Default false.
   723 	 *     @type bool         $sentence                Whether to search by phrase. Default false.
   721 	 *     @type bool         $suppress_filters        Whether to suppress filters. Default false.
   724 	 *     @type bool         $suppress_filters        Whether to suppress filters. Default false.
   722 	 *     @type string       $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
   725 	 *     @type string       $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
   723 	 *     @type array        $tag__and                An array of tag IDs (AND in).
   726 	 *     @type int[]        $tag__and                An array of tag IDs (AND in).
   724 	 *     @type array        $tag__in                 An array of tag IDs (OR in).
   727 	 *     @type int[]        $tag__in                 An array of tag IDs (OR in).
   725 	 *     @type array        $tag__not_in             An array of tag IDs (NOT in).
   728 	 *     @type int[]        $tag__not_in             An array of tag IDs (NOT in).
   726 	 *     @type int          $tag_id                  Tag id or comma-separated list of IDs.
   729 	 *     @type int          $tag_id                  Tag id or comma-separated list of IDs.
   727 	 *     @type array        $tag_slug__and           An array of tag slugs (AND in).
   730 	 *     @type string[]     $tag_slug__and           An array of tag slugs (AND in).
   728 	 *     @type array        $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
   731 	 *     @type string[]     $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
   729 	 *                                                 true. Note: a string of comma-separated IDs will NOT work.
   732 	 *                                                 true. Note: a string of comma-separated IDs will NOT work.
   730 	 *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
   733 	 *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
   731 	 *                                                 See WP_Tax_Query->queries.
   734 	 *                                                 See WP_Tax_Query->__construct().
   732 	 *     @type string       $title                   Post title.
   735 	 *     @type string       $title                   Post title.
   733 	 *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
   736 	 *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
   734 	 *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
   737 	 *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
   735 	 *     @type bool         $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
   738 	 *     @type bool         $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
   736 	 *                                                 disable cache priming for term meta, so that each
   739 	 *                                                 disable cache priming for term meta, so that each
   757 			$this->is_robots = true;
   760 			$this->is_robots = true;
   758 		} elseif ( ! empty( $qv['favicon'] ) ) {
   761 		} elseif ( ! empty( $qv['favicon'] ) ) {
   759 			$this->is_favicon = true;
   762 			$this->is_favicon = true;
   760 		}
   763 		}
   761 
   764 
   762 		if ( ! is_scalar( $qv['p'] ) || $qv['p'] < 0 ) {
   765 		if ( ! is_scalar( $qv['p'] ) || (int) $qv['p'] < 0 ) {
   763 			$qv['p']     = 0;
   766 			$qv['p']     = 0;
   764 			$qv['error'] = '404';
   767 			$qv['error'] = '404';
   765 		} else {
   768 		} else {
   766 			$qv['p'] = intval( $qv['p'] );
   769 			$qv['p'] = (int) $qv['p'];
   767 		}
   770 		}
   768 
   771 
   769 		$qv['page_id']  = absint( $qv['page_id'] );
   772 		$qv['page_id']  = absint( $qv['page_id'] );
   770 		$qv['year']     = absint( $qv['year'] );
   773 		$qv['year']     = absint( $qv['year'] );
   771 		$qv['monthnum'] = absint( $qv['monthnum'] );
   774 		$qv['monthnum'] = absint( $qv['monthnum'] );
   789 		}
   792 		}
   790 		if ( '' !== $qv['menu_order'] ) {
   793 		if ( '' !== $qv['menu_order'] ) {
   791 			$qv['menu_order'] = absint( $qv['menu_order'] );
   794 			$qv['menu_order'] = absint( $qv['menu_order'] );
   792 		}
   795 		}
   793 
   796 
   794 		// Fairly insane upper bound for search string lengths.
   797 		// Fairly large, potentially too large, upper bound for search string lengths.
   795 		if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) {
   798 		if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) {
   796 			$qv['s'] = '';
   799 			$qv['s'] = '';
   797 		}
   800 		}
   798 
   801 
   799 		// Compat. Map subpost to attachment.
   802 		// Compat. Map subpost to attachment.
   940 
   943 
   941 		if ( '' != $qv['tb'] ) {
   944 		if ( '' != $qv['tb'] ) {
   942 			$this->is_trackback = true;
   945 			$this->is_trackback = true;
   943 		}
   946 		}
   944 
   947 
   945 		if ( '' != $qv['paged'] && ( intval( $qv['paged'] ) > 1 ) ) {
   948 		if ( '' != $qv['paged'] && ( (int) $qv['paged'] > 1 ) ) {
   946 			$this->is_paged = true;
   949 			$this->is_paged = true;
   947 		}
   950 		}
   948 
   951 
   949 		// If we're previewing inside the write screen.
   952 		// If we're previewing inside the write screen.
   950 		if ( '' != $qv['preview'] ) {
   953 		if ( '' != $qv['preview'] ) {
  1073 		/**
  1076 		/**
  1074 		 * Fires after the main query vars have been parsed.
  1077 		 * Fires after the main query vars have been parsed.
  1075 		 *
  1078 		 *
  1076 		 * @since 1.5.0
  1079 		 * @since 1.5.0
  1077 		 *
  1080 		 *
  1078 		 * @param WP_Query $this The WP_Query instance (passed by reference).
  1081 		 * @param WP_Query $query The WP_Query instance (passed by reference).
  1079 		 */
  1082 		 */
  1080 		do_action_ref_array( 'parse_query', array( &$this ) );
  1083 		do_action_ref_array( 'parse_query', array( &$this ) );
  1081 	}
  1084 	}
  1082 
  1085 
  1083 	/**
  1086 	/**
  1113 				$tax_query_defaults = array(
  1116 				$tax_query_defaults = array(
  1114 					'taxonomy' => $taxonomy,
  1117 					'taxonomy' => $taxonomy,
  1115 					'field'    => 'slug',
  1118 					'field'    => 'slug',
  1116 				);
  1119 				);
  1117 
  1120 
  1118 				if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
  1121 				if ( ! empty( $t->rewrite['hierarchical'] ) ) {
  1119 					$q[ $t->query_var ] = wp_basename( $q[ $t->query_var ] );
  1122 					$q[ $t->query_var ] = wp_basename( $q[ $t->query_var ] );
  1120 				}
  1123 				}
  1121 
  1124 
  1122 				$term = $q[ $t->query_var ];
  1125 				$term = $q[ $t->query_var ];
  1123 
  1126 
  1314 		/**
  1317 		/**
  1315 		 * Fires after taxonomy-related query vars have been parsed.
  1318 		 * Fires after taxonomy-related query vars have been parsed.
  1316 		 *
  1319 		 *
  1317 		 * @since 3.7.0
  1320 		 * @since 3.7.0
  1318 		 *
  1321 		 *
  1319 		 * @param WP_Query $this The WP_Query instance.
  1322 		 * @param WP_Query $query The WP_Query instance.
  1320 		 */
  1323 		 */
  1321 		do_action( 'parse_tax_query', $this );
  1324 		do_action( 'parse_tax_query', $this );
  1322 	}
  1325 	}
  1323 
  1326 
  1324 	/**
  1327 	/**
  1602 		}
  1605 		}
  1603 
  1606 
  1604 		// If RAND() contains a seed value, sanitize and add to allowed keys.
  1607 		// If RAND() contains a seed value, sanitize and add to allowed keys.
  1605 		$rand_with_seed = false;
  1608 		$rand_with_seed = false;
  1606 		if ( preg_match( '/RAND\(([0-9]+)\)/i', $orderby, $matches ) ) {
  1609 		if ( preg_match( '/RAND\(([0-9]+)\)/i', $orderby, $matches ) ) {
  1607 			$orderby        = sprintf( 'RAND(%s)', intval( $matches[1] ) );
  1610 			$orderby        = sprintf( 'RAND(%s)', (int) $matches[1] );
  1608 			$allowed_keys[] = $orderby;
  1611 			$allowed_keys[] = $orderby;
  1609 			$rand_with_seed = true;
  1612 			$rand_with_seed = true;
  1610 		}
  1613 		}
  1611 
  1614 
  1612 		if ( ! in_array( $orderby, $allowed_keys, true ) ) {
  1615 		if ( ! in_array( $orderby, $allowed_keys, true ) ) {
  1713 		/**
  1716 		/**
  1714 		 * Fires after a 404 is triggered.
  1717 		 * Fires after a 404 is triggered.
  1715 		 *
  1718 		 *
  1716 		 * @since 5.5.0
  1719 		 * @since 5.5.0
  1717 		 *
  1720 		 *
  1718 		 * @param WP_Query $this The WP_Query instance (passed by reference).
  1721 		 * @param WP_Query $query The WP_Query instance (passed by reference).
  1719 		 */
  1722 		 */
  1720 		do_action_ref_array( 'set_404', array( $this ) );
  1723 		do_action_ref_array( 'set_404', array( $this ) );
  1721 	}
  1724 	}
  1722 
  1725 
  1723 	/**
  1726 	/**
  1724 	 * Retrieve query variable.
  1727 	 * Retrieves the value of a query variable.
  1725 	 *
  1728 	 *
  1726 	 * @since 1.5.0
  1729 	 * @since 1.5.0
  1727 	 * @since 3.9.0 The `$default` argument was introduced.
  1730 	 * @since 3.9.0 The `$default` argument was introduced.
  1728 	 *
  1731 	 *
  1729 	 * @param string $query_var Query variable key.
  1732 	 * @param string $query_var Query variable key.
  1730 	 * @param mixed  $default   Optional. Value to return if the query variable is not set. Default empty.
  1733 	 * @param mixed  $default   Optional. Value to return if the query variable is not set. Default empty string.
  1731 	 * @return mixed Contents of the query variable.
  1734 	 * @return mixed Contents of the query variable.
  1732 	 */
  1735 	 */
  1733 	public function get( $query_var, $default = '' ) {
  1736 	public function get( $query_var, $default = '' ) {
  1734 		if ( isset( $this->query_vars[ $query_var ] ) ) {
  1737 		if ( isset( $this->query_vars[ $query_var ] ) ) {
  1735 			return $this->query_vars[ $query_var ];
  1738 			return $this->query_vars[ $query_var ];
  1737 
  1740 
  1738 		return $default;
  1741 		return $default;
  1739 	}
  1742 	}
  1740 
  1743 
  1741 	/**
  1744 	/**
  1742 	 * Set query variable.
  1745 	 * Sets the value of a query variable.
  1743 	 *
  1746 	 *
  1744 	 * @since 1.5.0
  1747 	 * @since 1.5.0
  1745 	 *
  1748 	 *
  1746 	 * @param string $query_var Query variable key.
  1749 	 * @param string $query_var Query variable key.
  1747 	 * @param mixed  $value     Query variable value.
  1750 	 * @param mixed  $value     Query variable value.
  1755 	 *
  1758 	 *
  1756 	 * There are a few filters and actions that can be used to modify the post
  1759 	 * There are a few filters and actions that can be used to modify the post
  1757 	 * database query.
  1760 	 * database query.
  1758 	 *
  1761 	 *
  1759 	 * @since 1.5.0
  1762 	 * @since 1.5.0
       
  1763 	 *
       
  1764 	 * @global wpdb $wpdb WordPress database abstraction object.
  1760 	 *
  1765 	 *
  1761 	 * @return WP_Post[]|int[] Array of post objects or post IDs.
  1766 	 * @return WP_Post[]|int[] Array of post objects or post IDs.
  1762 	 */
  1767 	 */
  1763 	public function get_posts() {
  1768 	public function get_posts() {
  1764 		global $wpdb;
  1769 		global $wpdb;
  1772 		 * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions
  1777 		 * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions
  1773 		 * like is_main_query() test against the global $wp_query instance, not the passed one.
  1778 		 * like is_main_query() test against the global $wp_query instance, not the passed one.
  1774 		 *
  1779 		 *
  1775 		 * @since 2.0.0
  1780 		 * @since 2.0.0
  1776 		 *
  1781 		 *
  1777 		 * @param WP_Query $this The WP_Query instance (passed by reference).
  1782 		 * @param WP_Query $query The WP_Query instance (passed by reference).
  1778 		 */
  1783 		 */
  1779 		do_action_ref_array( 'pre_get_posts', array( &$this ) );
  1784 		do_action_ref_array( 'pre_get_posts', array( &$this ) );
  1780 
  1785 
  1781 		// Shorthand.
  1786 		// Shorthand.
  1782 		$q = &$this->query_vars;
  1787 		$q = &$this->query_vars;
  2119 			 * Filters the search SQL that is used in the WHERE clause of WP_Query.
  2124 			 * Filters the search SQL that is used in the WHERE clause of WP_Query.
  2120 			 *
  2125 			 *
  2121 			 * @since 3.0.0
  2126 			 * @since 3.0.0
  2122 			 *
  2127 			 *
  2123 			 * @param string   $search Search SQL for WHERE clause.
  2128 			 * @param string   $search Search SQL for WHERE clause.
  2124 			 * @param WP_Query $this   The current WP_Query object.
  2129 			 * @param WP_Query $query  The current WP_Query object.
  2125 			 */
  2130 			 */
  2126 			$search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) );
  2131 			$search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) );
  2127 		}
  2132 		}
  2128 
  2133 
  2129 		// Taxonomies.
  2134 		// Taxonomies.
  2261 		// Matching by comment count.
  2266 		// Matching by comment count.
  2262 		if ( isset( $q['comment_count'] ) ) {
  2267 		if ( isset( $q['comment_count'] ) ) {
  2263 			// Numeric comment count is converted to array format.
  2268 			// Numeric comment count is converted to array format.
  2264 			if ( is_numeric( $q['comment_count'] ) ) {
  2269 			if ( is_numeric( $q['comment_count'] ) ) {
  2265 				$q['comment_count'] = array(
  2270 				$q['comment_count'] = array(
  2266 					'value' => intval( $q['comment_count'] ),
  2271 					'value' => (int) $q['comment_count'],
  2267 				);
  2272 				);
  2268 			}
  2273 			}
  2269 
  2274 
  2270 			if ( isset( $q['comment_count']['value'] ) ) {
  2275 			if ( isset( $q['comment_count']['value'] ) ) {
  2271 				$q['comment_count'] = array_merge(
  2276 				$q['comment_count'] = array_merge(
  2374 				 * Filters the ORDER BY used when ordering search results.
  2379 				 * Filters the ORDER BY used when ordering search results.
  2375 				 *
  2380 				 *
  2376 				 * @since 3.7.0
  2381 				 * @since 3.7.0
  2377 				 *
  2382 				 *
  2378 				 * @param string   $search_orderby The ORDER BY clause.
  2383 				 * @param string   $search_orderby The ORDER BY clause.
  2379 				 * @param WP_Query $this           The current WP_Query instance.
  2384 				 * @param WP_Query $query          The current WP_Query instance.
  2380 				 */
  2385 				 */
  2381 				$search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this );
  2386 				$search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this );
  2382 			}
  2387 			}
  2383 
  2388 
  2384 			if ( $search_orderby ) {
  2389 			if ( $search_orderby ) {
  2418 		if ( 'any' === $post_type ) {
  2423 		if ( 'any' === $post_type ) {
  2419 			$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
  2424 			$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
  2420 			if ( empty( $in_search_post_types ) ) {
  2425 			if ( empty( $in_search_post_types ) ) {
  2421 				$where .= ' AND 1=0 ';
  2426 				$where .= ' AND 1=0 ';
  2422 			} else {
  2427 			} else {
  2423 				$where .= " AND {$wpdb->posts}.post_type IN ('" . join( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
  2428 				$where .= " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
  2424 			}
  2429 			}
  2425 		} elseif ( ! empty( $post_type ) && is_array( $post_type ) ) {
  2430 		} elseif ( ! empty( $post_type ) && is_array( $post_type ) ) {
  2426 			$where .= " AND {$wpdb->posts}.post_type IN ('" . join( "', '", esc_sql( $post_type ) ) . "')";
  2431 			$where .= " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
  2427 		} elseif ( ! empty( $post_type ) ) {
  2432 		} elseif ( ! empty( $post_type ) ) {
  2428 			$where           .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
  2433 			$where           .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
  2429 			$post_type_object = get_post_type_object( $post_type );
  2434 			$post_type_object = get_post_type_object( $post_type );
  2430 		} elseif ( $this->is_attachment ) {
  2435 		} elseif ( $this->is_attachment ) {
  2431 			$where           .= " AND {$wpdb->posts}.post_type = 'attachment'";
  2436 			$where           .= " AND {$wpdb->posts}.post_type = 'attachment'";
  2483 				$r_status = array_merge( $r_status, $p_status );
  2488 				$r_status = array_merge( $r_status, $p_status );
  2484 				unset( $p_status );
  2489 				unset( $p_status );
  2485 			}
  2490 			}
  2486 
  2491 
  2487 			if ( ! empty( $e_status ) ) {
  2492 			if ( ! empty( $e_status ) ) {
  2488 				$statuswheres[] = '(' . join( ' AND ', $e_status ) . ')';
  2493 				$statuswheres[] = '(' . implode( ' AND ', $e_status ) . ')';
  2489 			}
  2494 			}
  2490 			if ( ! empty( $r_status ) ) {
  2495 			if ( ! empty( $r_status ) ) {
  2491 				if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
  2496 				if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
  2492 					$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $r_status ) . '))';
  2497 					$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $r_status ) . '))';
  2493 				} else {
  2498 				} else {
  2494 					$statuswheres[] = '(' . join( ' OR ', $r_status ) . ')';
  2499 					$statuswheres[] = '(' . implode( ' OR ', $r_status ) . ')';
  2495 				}
  2500 				}
  2496 			}
  2501 			}
  2497 			if ( ! empty( $p_status ) ) {
  2502 			if ( ! empty( $p_status ) ) {
  2498 				if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) {
  2503 				if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) {
  2499 					$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $p_status ) . '))';
  2504 					$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $p_status ) . '))';
  2500 				} else {
  2505 				} else {
  2501 					$statuswheres[] = '(' . join( ' OR ', $p_status ) . ')';
  2506 					$statuswheres[] = '(' . implode( ' OR ', $p_status ) . ')';
  2502 				}
  2507 				}
  2503 			}
  2508 			}
  2504 			if ( $post_status_join ) {
  2509 			if ( $post_status_join ) {
  2505 				$join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) ";
  2510 				$join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) ";
  2506 				foreach ( $statuswheres as $index => $statuswhere ) {
  2511 				foreach ( $statuswheres as $index => $statuswhere ) {
  2556 			 * Filters the WHERE clause of the query.
  2561 			 * Filters the WHERE clause of the query.
  2557 			 *
  2562 			 *
  2558 			 * @since 1.5.0
  2563 			 * @since 1.5.0
  2559 			 *
  2564 			 *
  2560 			 * @param string   $where The WHERE clause of the query.
  2565 			 * @param string   $where The WHERE clause of the query.
  2561 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  2566 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  2562 			 */
  2567 			 */
  2563 			$where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) );
  2568 			$where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) );
  2564 
  2569 
  2565 			/**
  2570 			/**
  2566 			 * Filters the JOIN clause of the query.
  2571 			 * Filters the JOIN clause of the query.
  2567 			 *
  2572 			 *
  2568 			 * @since 1.5.0
  2573 			 * @since 1.5.0
  2569 			 *
  2574 			 *
  2570 			 * @param string   $join  The JOIN clause of the query.
  2575 			 * @param string   $join  The JOIN clause of the query.
  2571 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  2576 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  2572 			 */
  2577 			 */
  2573 			$join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) );
  2578 			$join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) );
  2574 		}
  2579 		}
  2575 
  2580 
  2576 		// Paging.
  2581 		// Paging.
  2591 		}
  2596 		}
  2592 
  2597 
  2593 		// Comments feeds.
  2598 		// Comments feeds.
  2594 		if ( $this->is_comment_feed && ! $this->is_singular ) {
  2599 		if ( $this->is_comment_feed && ! $this->is_singular ) {
  2595 			if ( $this->is_archive || $this->is_search ) {
  2600 			if ( $this->is_archive || $this->is_search ) {
  2596 				$cjoin    = "JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) $join ";
  2601 				$cjoin    = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID ) $join ";
  2597 				$cwhere   = "WHERE comment_approved = '1' $where";
  2602 				$cwhere   = "WHERE comment_approved = '1' $where";
  2598 				$cgroupby = "{$wpdb->comments}.comment_id";
  2603 				$cgroupby = "{$wpdb->comments}.comment_id";
  2599 			} else { // Other non-singular, e.g. front.
  2604 			} else { // Other non-singular, e.g. front.
  2600 				$cjoin    = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )";
  2605 				$cjoin    = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )";
  2601 				$cwhere   = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'";
  2606 				$cwhere   = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'";
  2607 				 * Filters the JOIN clause of the comments feed query before sending.
  2612 				 * Filters the JOIN clause of the comments feed query before sending.
  2608 				 *
  2613 				 *
  2609 				 * @since 2.2.0
  2614 				 * @since 2.2.0
  2610 				 *
  2615 				 *
  2611 				 * @param string   $cjoin The JOIN clause of the query.
  2616 				 * @param string   $cjoin The JOIN clause of the query.
  2612 				 * @param WP_Query $this The WP_Query instance (passed by reference).
  2617 				 * @param WP_Query $query The WP_Query instance (passed by reference).
  2613 				 */
  2618 				 */
  2614 				$cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) );
  2619 				$cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) );
  2615 
  2620 
  2616 				/**
  2621 				/**
  2617 				 * Filters the WHERE clause of the comments feed query before sending.
  2622 				 * Filters the WHERE clause of the comments feed query before sending.
  2618 				 *
  2623 				 *
  2619 				 * @since 2.2.0
  2624 				 * @since 2.2.0
  2620 				 *
  2625 				 *
  2621 				 * @param string   $cwhere The WHERE clause of the query.
  2626 				 * @param string   $cwhere The WHERE clause of the query.
  2622 				 * @param WP_Query $this   The WP_Query instance (passed by reference).
  2627 				 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2623 				 */
  2628 				 */
  2624 				$cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) );
  2629 				$cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) );
  2625 
  2630 
  2626 				/**
  2631 				/**
  2627 				 * Filters the GROUP BY clause of the comments feed query before sending.
  2632 				 * Filters the GROUP BY clause of the comments feed query before sending.
  2628 				 *
  2633 				 *
  2629 				 * @since 2.2.0
  2634 				 * @since 2.2.0
  2630 				 *
  2635 				 *
  2631 				 * @param string   $cgroupby The GROUP BY clause of the query.
  2636 				 * @param string   $cgroupby The GROUP BY clause of the query.
  2632 				 * @param WP_Query $this     The WP_Query instance (passed by reference).
  2637 				 * @param WP_Query $query    The WP_Query instance (passed by reference).
  2633 				 */
  2638 				 */
  2634 				$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) );
  2639 				$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) );
  2635 
  2640 
  2636 				/**
  2641 				/**
  2637 				 * Filters the ORDER BY clause of the comments feed query before sending.
  2642 				 * Filters the ORDER BY clause of the comments feed query before sending.
  2638 				 *
  2643 				 *
  2639 				 * @since 2.8.0
  2644 				 * @since 2.8.0
  2640 				 *
  2645 				 *
  2641 				 * @param string   $corderby The ORDER BY clause of the query.
  2646 				 * @param string   $corderby The ORDER BY clause of the query.
  2642 				 * @param WP_Query $this     The WP_Query instance (passed by reference).
  2647 				 * @param WP_Query $query    The WP_Query instance (passed by reference).
  2643 				 */
  2648 				 */
  2644 				$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
  2649 				$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
  2645 
  2650 
  2646 				/**
  2651 				/**
  2647 				 * Filters the LIMIT clause of the comments feed query before sending.
  2652 				 * Filters the LIMIT clause of the comments feed query before sending.
  2648 				 *
  2653 				 *
  2649 				 * @since 2.8.0
  2654 				 * @since 2.8.0
  2650 				 *
  2655 				 *
  2651 				 * @param string   $climits The JOIN clause of the query.
  2656 				 * @param string   $climits The JOIN clause of the query.
  2652 				 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2657 				 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2653 				 */
  2658 				 */
  2654 				$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
  2659 				$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
  2655 			}
  2660 			}
  2656 
  2661 
  2657 			$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
  2662 			$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
  2658 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
  2663 			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
  2659 			$climits  = ( ! empty( $climits ) ) ? $climits : '';
  2664 			$climits  = ( ! empty( $climits ) ) ? $climits : '';
  2660 
  2665 
  2661 			$comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" );
  2666 			$comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" );
  2662 			// Convert to WP_Comment.
  2667 			// Convert to WP_Comment.
       
  2668 			/** @var WP_Comment[] */
  2663 			$this->comments      = array_map( 'get_comment', $comments );
  2669 			$this->comments      = array_map( 'get_comment', $comments );
  2664 			$this->comment_count = count( $this->comments );
  2670 			$this->comment_count = count( $this->comments );
  2665 
  2671 
  2666 			$post_ids = array();
  2672 			$post_ids = array();
  2667 
  2673 
  2668 			foreach ( $this->comments as $comment ) {
  2674 			foreach ( $this->comments as $comment ) {
  2669 				$post_ids[] = (int) $comment->comment_post_ID;
  2675 				$post_ids[] = (int) $comment->comment_post_ID;
  2670 			}
  2676 			}
  2671 
  2677 
  2672 			$post_ids = join( ',', $post_ids );
  2678 			$post_ids = implode( ',', $post_ids );
  2673 			$join     = '';
  2679 			$join     = '';
  2674 			if ( $post_ids ) {
  2680 			if ( $post_ids ) {
  2675 				$where = "AND {$wpdb->posts}.ID IN ($post_ids) ";
  2681 				$where = "AND {$wpdb->posts}.ID IN ($post_ids) ";
  2676 			} else {
  2682 			} else {
  2677 				$where = 'AND 0';
  2683 				$where = 'AND 0';
  2691 			 * Specifically for manipulating paging queries.
  2697 			 * Specifically for manipulating paging queries.
  2692 			 *
  2698 			 *
  2693 			 * @since 1.5.0
  2699 			 * @since 1.5.0
  2694 			 *
  2700 			 *
  2695 			 * @param string   $where The WHERE clause of the query.
  2701 			 * @param string   $where The WHERE clause of the query.
  2696 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  2702 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  2697 			 */
  2703 			 */
  2698 			$where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
  2704 			$where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
  2699 
  2705 
  2700 			/**
  2706 			/**
  2701 			 * Filters the GROUP BY clause of the query.
  2707 			 * Filters the GROUP BY clause of the query.
  2702 			 *
  2708 			 *
  2703 			 * @since 2.0.0
  2709 			 * @since 2.0.0
  2704 			 *
  2710 			 *
  2705 			 * @param string   $groupby The GROUP BY clause of the query.
  2711 			 * @param string   $groupby The GROUP BY clause of the query.
  2706 			 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2712 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2707 			 */
  2713 			 */
  2708 			$groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) );
  2714 			$groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) );
  2709 
  2715 
  2710 			/**
  2716 			/**
  2711 			 * Filters the JOIN clause of the query.
  2717 			 * Filters the JOIN clause of the query.
  2713 			 * Specifically for manipulating paging queries.
  2719 			 * Specifically for manipulating paging queries.
  2714 			 *
  2720 			 *
  2715 			 * @since 1.5.0
  2721 			 * @since 1.5.0
  2716 			 *
  2722 			 *
  2717 			 * @param string   $join  The JOIN clause of the query.
  2723 			 * @param string   $join  The JOIN clause of the query.
  2718 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  2724 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  2719 			 */
  2725 			 */
  2720 			$join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) );
  2726 			$join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) );
  2721 
  2727 
  2722 			/**
  2728 			/**
  2723 			 * Filters the ORDER BY clause of the query.
  2729 			 * Filters the ORDER BY clause of the query.
  2724 			 *
  2730 			 *
  2725 			 * @since 1.5.1
  2731 			 * @since 1.5.1
  2726 			 *
  2732 			 *
  2727 			 * @param string   $orderby The ORDER BY clause of the query.
  2733 			 * @param string   $orderby The ORDER BY clause of the query.
  2728 			 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2734 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2729 			 */
  2735 			 */
  2730 			$orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) );
  2736 			$orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) );
  2731 
  2737 
  2732 			/**
  2738 			/**
  2733 			 * Filters the DISTINCT clause of the query.
  2739 			 * Filters the DISTINCT clause of the query.
  2734 			 *
  2740 			 *
  2735 			 * @since 2.1.0
  2741 			 * @since 2.1.0
  2736 			 *
  2742 			 *
  2737 			 * @param string   $distinct The DISTINCT clause of the query.
  2743 			 * @param string   $distinct The DISTINCT clause of the query.
  2738 			 * @param WP_Query $this     The WP_Query instance (passed by reference).
  2744 			 * @param WP_Query $query    The WP_Query instance (passed by reference).
  2739 			 */
  2745 			 */
  2740 			$distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) );
  2746 			$distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) );
  2741 
  2747 
  2742 			/**
  2748 			/**
  2743 			 * Filters the LIMIT clause of the query.
  2749 			 * Filters the LIMIT clause of the query.
  2744 			 *
  2750 			 *
  2745 			 * @since 2.1.0
  2751 			 * @since 2.1.0
  2746 			 *
  2752 			 *
  2747 			 * @param string   $limits The LIMIT clause of the query.
  2753 			 * @param string   $limits The LIMIT clause of the query.
  2748 			 * @param WP_Query $this   The WP_Query instance (passed by reference).
  2754 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2749 			 */
  2755 			 */
  2750 			$limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) );
  2756 			$limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) );
  2751 
  2757 
  2752 			/**
  2758 			/**
  2753 			 * Filters the SELECT clause of the query.
  2759 			 * Filters the SELECT clause of the query.
  2754 			 *
  2760 			 *
  2755 			 * @since 2.1.0
  2761 			 * @since 2.1.0
  2756 			 *
  2762 			 *
  2757 			 * @param string   $fields The SELECT clause of the query.
  2763 			 * @param string   $fields The SELECT clause of the query.
  2758 			 * @param WP_Query $this   The WP_Query instance (passed by reference).
  2764 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2759 			 */
  2765 			 */
  2760 			$fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) );
  2766 			$fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) );
  2761 
  2767 
  2762 			/**
  2768 			/**
  2763 			 * Filters all query clauses at once, for convenience.
  2769 			 * Filters all query clauses at once, for convenience.
  2766 			 * fields (SELECT), and LIMITS clauses.
  2772 			 * fields (SELECT), and LIMITS clauses.
  2767 			 *
  2773 			 *
  2768 			 * @since 3.1.0
  2774 			 * @since 3.1.0
  2769 			 *
  2775 			 *
  2770 			 * @param string[] $clauses Associative array of the clauses for the query.
  2776 			 * @param string[] $clauses Associative array of the clauses for the query.
  2771 			 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2777 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2772 			 */
  2778 			 */
  2773 			$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
  2779 			$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
  2774 
  2780 
  2775 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2781 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2776 			$groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
  2782 			$groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
  2803 			 * For use by caching plugins.
  2809 			 * For use by caching plugins.
  2804 			 *
  2810 			 *
  2805 			 * @since 2.5.0
  2811 			 * @since 2.5.0
  2806 			 *
  2812 			 *
  2807 			 * @param string   $where The WHERE clause of the query.
  2813 			 * @param string   $where The WHERE clause of the query.
  2808 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  2814 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  2809 			 */
  2815 			 */
  2810 			$where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) );
  2816 			$where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) );
  2811 
  2817 
  2812 			/**
  2818 			/**
  2813 			 * Filters the GROUP BY clause of the query.
  2819 			 * Filters the GROUP BY clause of the query.
  2815 			 * For use by caching plugins.
  2821 			 * For use by caching plugins.
  2816 			 *
  2822 			 *
  2817 			 * @since 2.5.0
  2823 			 * @since 2.5.0
  2818 			 *
  2824 			 *
  2819 			 * @param string   $groupby The GROUP BY clause of the query.
  2825 			 * @param string   $groupby The GROUP BY clause of the query.
  2820 			 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2826 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2821 			 */
  2827 			 */
  2822 			$groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) );
  2828 			$groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) );
  2823 
  2829 
  2824 			/**
  2830 			/**
  2825 			 * Filters the JOIN clause of the query.
  2831 			 * Filters the JOIN clause of the query.
  2827 			 * For use by caching plugins.
  2833 			 * For use by caching plugins.
  2828 			 *
  2834 			 *
  2829 			 * @since 2.5.0
  2835 			 * @since 2.5.0
  2830 			 *
  2836 			 *
  2831 			 * @param string   $join  The JOIN clause of the query.
  2837 			 * @param string   $join  The JOIN clause of the query.
  2832 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  2838 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  2833 			 */
  2839 			 */
  2834 			$join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) );
  2840 			$join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) );
  2835 
  2841 
  2836 			/**
  2842 			/**
  2837 			 * Filters the ORDER BY clause of the query.
  2843 			 * Filters the ORDER BY clause of the query.
  2839 			 * For use by caching plugins.
  2845 			 * For use by caching plugins.
  2840 			 *
  2846 			 *
  2841 			 * @since 2.5.0
  2847 			 * @since 2.5.0
  2842 			 *
  2848 			 *
  2843 			 * @param string   $orderby The ORDER BY clause of the query.
  2849 			 * @param string   $orderby The ORDER BY clause of the query.
  2844 			 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2850 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2845 			 */
  2851 			 */
  2846 			$orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) );
  2852 			$orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) );
  2847 
  2853 
  2848 			/**
  2854 			/**
  2849 			 * Filters the DISTINCT clause of the query.
  2855 			 * Filters the DISTINCT clause of the query.
  2851 			 * For use by caching plugins.
  2857 			 * For use by caching plugins.
  2852 			 *
  2858 			 *
  2853 			 * @since 2.5.0
  2859 			 * @since 2.5.0
  2854 			 *
  2860 			 *
  2855 			 * @param string   $distinct The DISTINCT clause of the query.
  2861 			 * @param string   $distinct The DISTINCT clause of the query.
  2856 			 * @param WP_Query $this     The WP_Query instance (passed by reference).
  2862 			 * @param WP_Query $query    The WP_Query instance (passed by reference).
  2857 			 */
  2863 			 */
  2858 			$distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) );
  2864 			$distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) );
  2859 
  2865 
  2860 			/**
  2866 			/**
  2861 			 * Filters the SELECT clause of the query.
  2867 			 * Filters the SELECT clause of the query.
  2863 			 * For use by caching plugins.
  2869 			 * For use by caching plugins.
  2864 			 *
  2870 			 *
  2865 			 * @since 2.5.0
  2871 			 * @since 2.5.0
  2866 			 *
  2872 			 *
  2867 			 * @param string   $fields The SELECT clause of the query.
  2873 			 * @param string   $fields The SELECT clause of the query.
  2868 			 * @param WP_Query $this   The WP_Query instance (passed by reference).
  2874 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2869 			 */
  2875 			 */
  2870 			$fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) );
  2876 			$fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) );
  2871 
  2877 
  2872 			/**
  2878 			/**
  2873 			 * Filters the LIMIT clause of the query.
  2879 			 * Filters the LIMIT clause of the query.
  2875 			 * For use by caching plugins.
  2881 			 * For use by caching plugins.
  2876 			 *
  2882 			 *
  2877 			 * @since 2.5.0
  2883 			 * @since 2.5.0
  2878 			 *
  2884 			 *
  2879 			 * @param string   $limits The LIMIT clause of the query.
  2885 			 * @param string   $limits The LIMIT clause of the query.
  2880 			 * @param WP_Query $this   The WP_Query instance (passed by reference).
  2886 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2881 			 */
  2887 			 */
  2882 			$limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) );
  2888 			$limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) );
  2883 
  2889 
  2884 			/**
  2890 			/**
  2885 			 * Filters all query clauses at once, for convenience.
  2891 			 * Filters all query clauses at once, for convenience.
  2890 			 * fields (SELECT), and LIMITS clauses.
  2896 			 * fields (SELECT), and LIMITS clauses.
  2891 			 *
  2897 			 *
  2892 			 * @since 3.1.0
  2898 			 * @since 3.1.0
  2893 			 *
  2899 			 *
  2894 			 * @param string[] $pieces Associative array of the pieces of the query.
  2900 			 * @param string[] $pieces Associative array of the pieces of the query.
  2895 			 * @param WP_Query $this   The WP_Query instance (passed by reference).
  2901 			 * @param WP_Query $query  The WP_Query instance (passed by reference).
  2896 			 */
  2902 			 */
  2897 			$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
  2903 			$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
  2898 
  2904 
  2899 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2905 			$where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
  2900 			$groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
  2906 			$groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
  2925 			 * Filters the completed SQL query before sending.
  2931 			 * Filters the completed SQL query before sending.
  2926 			 *
  2932 			 *
  2927 			 * @since 2.0.0
  2933 			 * @since 2.0.0
  2928 			 *
  2934 			 *
  2929 			 * @param string   $request The complete SQL query.
  2935 			 * @param string   $request The complete SQL query.
  2930 			 * @param WP_Query $this    The WP_Query instance (passed by reference).
  2936 			 * @param WP_Query $query   The WP_Query instance (passed by reference).
  2931 			 */
  2937 			 */
  2932 			$this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) );
  2938 			$this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) );
  2933 		}
  2939 		}
  2934 
  2940 
  2935 		/**
  2941 		/**
  2936 		 * Filters the posts array before the query takes place.
  2942 		 * Filters the posts array before the query takes place.
  2937 		 *
  2943 		 *
  2938 		 * Return a non-null value to bypass WordPress's default post queries.
  2944 		 * Return a non-null value to bypass WordPress' default post queries.
  2939 		 *
  2945 		 *
  2940 		 * Filtering functions that require pagination information are encouraged to set
  2946 		 * Filtering functions that require pagination information are encouraged to set
  2941 		 * the `found_posts` and `max_num_pages` properties of the WP_Query object,
  2947 		 * the `found_posts` and `max_num_pages` properties of the WP_Query object,
  2942 		 * passed to the filter by reference. If WP_Query does not perform a database
  2948 		 * passed to the filter by reference. If WP_Query does not perform a database
  2943 		 * query, it will not have enough information to generate these values itself.
  2949 		 * query, it will not have enough information to generate these values itself.
  2944 		 *
  2950 		 *
  2945 		 * @since 4.6.0
  2951 		 * @since 4.6.0
  2946 		 *
  2952 		 *
  2947 		 * @param array|null $posts Return an array of post data to short-circuit WP's query,
  2953 		 * @param WP_Post[]|int[]|null $posts Return an array of post data to short-circuit WP's query,
  2948 		 *                          or null to allow WP to run its normal queries.
  2954 		 *                                    or null to allow WP to run its normal queries.
  2949 		 * @param WP_Query   $this  The WP_Query instance (passed by reference).
  2955 		 * @param WP_Query             $query The WP_Query instance (passed by reference).
  2950 		 */
  2956 		 */
  2951 		$this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );
  2957 		$this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );
  2952 
  2958 
  2953 		if ( 'ids' === $q['fields'] ) {
  2959 		if ( 'ids' === $q['fields'] ) {
  2954 			if ( null === $this->posts ) {
  2960 			if ( null === $this->posts ) {
  2955 				$this->posts = $wpdb->get_col( $this->request );
  2961 				$this->posts = $wpdb->get_col( $this->request );
  2956 			}
  2962 			}
  2957 
  2963 
       
  2964 			/** @var int[] */
  2958 			$this->posts      = array_map( 'intval', $this->posts );
  2965 			$this->posts      = array_map( 'intval', $this->posts );
  2959 			$this->post_count = count( $this->posts );
  2966 			$this->post_count = count( $this->posts );
  2960 			$this->set_found_posts( $q, $limits );
  2967 			$this->set_found_posts( $q, $limits );
  2961 
  2968 
  2962 			return $this->posts;
  2969 			return $this->posts;
  2968 			}
  2975 			}
  2969 
  2976 
  2970 			$this->post_count = count( $this->posts );
  2977 			$this->post_count = count( $this->posts );
  2971 			$this->set_found_posts( $q, $limits );
  2978 			$this->set_found_posts( $q, $limits );
  2972 
  2979 
       
  2980 			/** @var int[] */
  2973 			$r = array();
  2981 			$r = array();
  2974 			foreach ( $this->posts as $key => $post ) {
  2982 			foreach ( $this->posts as $key => $post ) {
  2975 				$this->posts[ $key ]->ID          = (int) $post->ID;
  2983 				$this->posts[ $key ]->ID          = (int) $post->ID;
  2976 				$this->posts[ $key ]->post_parent = (int) $post->post_parent;
  2984 				$this->posts[ $key ]->post_parent = (int) $post->post_parent;
  2977 
  2985 
  2992 			 * complete row at once. One massive result vs. many small results.
  3000 			 * complete row at once. One massive result vs. many small results.
  2993 			 *
  3001 			 *
  2994 			 * @since 3.4.0
  3002 			 * @since 3.4.0
  2995 			 *
  3003 			 *
  2996 			 * @param bool     $split_the_query Whether or not to split the query.
  3004 			 * @param bool     $split_the_query Whether or not to split the query.
  2997 			 * @param WP_Query $this            The WP_Query instance.
  3005 			 * @param WP_Query $query           The WP_Query instance.
  2998 			 */
  3006 			 */
  2999 			$split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
  3007 			$split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
  3000 
  3008 
  3001 			if ( $split_the_query ) {
  3009 			if ( $split_the_query ) {
  3002 				// First get the IDs and then fill in the objects.
  3010 				// First get the IDs and then fill in the objects.
  3007 				 * Filters the Post IDs SQL request before sending.
  3015 				 * Filters the Post IDs SQL request before sending.
  3008 				 *
  3016 				 *
  3009 				 * @since 3.4.0
  3017 				 * @since 3.4.0
  3010 				 *
  3018 				 *
  3011 				 * @param string   $request The post ID request.
  3019 				 * @param string   $request The post ID request.
  3012 				 * @param WP_Query $this    The WP_Query instance.
  3020 				 * @param WP_Query $query   The WP_Query instance.
  3013 				 */
  3021 				 */
  3014 				$this->request = apply_filters( 'posts_request_ids', $this->request, $this );
  3022 				$this->request = apply_filters( 'posts_request_ids', $this->request, $this );
  3015 
  3023 
  3016 				$ids = $wpdb->get_col( $this->request );
  3024 				$ids = $wpdb->get_col( $this->request );
  3017 
  3025 
  3028 			}
  3036 			}
  3029 		}
  3037 		}
  3030 
  3038 
  3031 		// Convert to WP_Post objects.
  3039 		// Convert to WP_Post objects.
  3032 		if ( $this->posts ) {
  3040 		if ( $this->posts ) {
       
  3041 			/** @var WP_Post[] */
  3033 			$this->posts = array_map( 'get_post', $this->posts );
  3042 			$this->posts = array_map( 'get_post', $this->posts );
  3034 		}
  3043 		}
  3035 
  3044 
  3036 		if ( ! $q['suppress_filters'] ) {
  3045 		if ( ! $q['suppress_filters'] ) {
  3037 			/**
  3046 			/**
  3038 			 * Filters the raw post results array, prior to status checks.
  3047 			 * Filters the raw post results array, prior to status checks.
  3039 			 *
  3048 			 *
  3040 			 * @since 2.3.0
  3049 			 * @since 2.3.0
  3041 			 *
  3050 			 *
  3042 			 * @param WP_Post[] $posts Array of post objects.
  3051 			 * @param WP_Post[] $posts Array of post objects.
  3043 			 * @param WP_Query  $this  The WP_Query instance (passed by reference).
  3052 			 * @param WP_Query  $query The WP_Query instance (passed by reference).
  3044 			 */
  3053 			 */
  3045 			$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
  3054 			$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
  3046 		}
  3055 		}
  3047 
  3056 
  3048 		if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) {
  3057 		if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) {
  3064 			$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
  3073 			$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
  3065 
  3074 
  3066 			$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
  3075 			$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
  3067 			$comments         = $wpdb->get_results( $comments_request );
  3076 			$comments         = $wpdb->get_results( $comments_request );
  3068 			// Convert to WP_Comment.
  3077 			// Convert to WP_Comment.
       
  3078 			/** @var WP_Comment[] */
  3069 			$this->comments      = array_map( 'get_comment', $comments );
  3079 			$this->comments      = array_map( 'get_comment', $comments );
  3070 			$this->comment_count = count( $this->comments );
  3080 			$this->comment_count = count( $this->comments );
  3071 		}
  3081 		}
  3072 
  3082 
  3073 		// Check post status to determine if post should be displayed.
  3083 		// Check post status to determine if post should be displayed.
  3120 				 * Filters the single post for preview mode.
  3130 				 * Filters the single post for preview mode.
  3121 				 *
  3131 				 *
  3122 				 * @since 2.7.0
  3132 				 * @since 2.7.0
  3123 				 *
  3133 				 *
  3124 				 * @param WP_Post  $post_preview  The Post object.
  3134 				 * @param WP_Post  $post_preview  The Post object.
  3125 				 * @param WP_Query $this          The WP_Query instance (passed by reference).
  3135 				 * @param WP_Query $query         The WP_Query instance (passed by reference).
  3126 				 */
  3136 				 */
  3127 				$this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) );
  3137 				$this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) );
  3128 			}
  3138 			}
  3129 		}
  3139 		}
  3130 
  3140 
  3183 			 * internally processed.
  3193 			 * internally processed.
  3184 			 *
  3194 			 *
  3185 			 * @since 1.5.0
  3195 			 * @since 1.5.0
  3186 			 *
  3196 			 *
  3187 			 * @param WP_Post[] $posts Array of post objects.
  3197 			 * @param WP_Post[] $posts Array of post objects.
  3188 			 * @param WP_Query  $this The WP_Query instance (passed by reference).
  3198 			 * @param WP_Query  $query The WP_Query instance (passed by reference).
  3189 			 */
  3199 			 */
  3190 			$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );
  3200 			$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );
  3191 		}
  3201 		}
  3192 
  3202 
  3193 		// Ensure that any posts added/modified via one of the filters above are
  3203 		// Ensure that any posts added/modified via one of the filters above are
  3194 		// of the type WP_Post and are filtered.
  3204 		// of the type WP_Post and are filtered.
  3195 		if ( $this->posts ) {
  3205 		if ( $this->posts ) {
  3196 			$this->post_count = count( $this->posts );
  3206 			$this->post_count = count( $this->posts );
  3197 
  3207 
       
  3208 			/** @var WP_Post[] */
  3198 			$this->posts = array_map( 'get_post', $this->posts );
  3209 			$this->posts = array_map( 'get_post', $this->posts );
  3199 
  3210 
  3200 			if ( $q['cache_results'] ) {
  3211 			if ( $q['cache_results'] ) {
  3201 				update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
  3212 				update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
  3202 			}
  3213 			}
  3203 
  3214 
       
  3215 			/** @var WP_Post */
  3204 			$this->post = reset( $this->posts );
  3216 			$this->post = reset( $this->posts );
  3205 		} else {
  3217 		} else {
  3206 			$this->post_count = 0;
  3218 			$this->post_count = 0;
  3207 			$this->posts      = array();
  3219 			$this->posts      = array();
  3208 		}
  3220 		}
  3218 	 * Set up the amount of found posts and the number of pages (if limit clause was used)
  3230 	 * Set up the amount of found posts and the number of pages (if limit clause was used)
  3219 	 * for the current query.
  3231 	 * for the current query.
  3220 	 *
  3232 	 *
  3221 	 * @since 3.5.0
  3233 	 * @since 3.5.0
  3222 	 *
  3234 	 *
       
  3235 	 * @global wpdb $wpdb WordPress database abstraction object.
       
  3236 	 *
  3223 	 * @param array  $q      Query variables.
  3237 	 * @param array  $q      Query variables.
  3224 	 * @param string $limits LIMIT clauses of the query.
  3238 	 * @param string $limits LIMIT clauses of the query.
  3225 	 */
  3239 	 */
  3226 	private function set_found_posts( $q, $limits ) {
  3240 	private function set_found_posts( $q, $limits ) {
  3227 		global $wpdb;
  3241 		global $wpdb;
       
  3242 
  3228 		// Bail if posts is an empty array. Continue if posts is an empty string,
  3243 		// Bail if posts is an empty array. Continue if posts is an empty string,
  3229 		// null, or false to accommodate caching plugins that fill posts later.
  3244 		// null, or false to accommodate caching plugins that fill posts later.
  3230 		if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) {
  3245 		if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) {
  3231 			return;
  3246 			return;
  3232 		}
  3247 		}
  3236 			 * Filters the query to run for retrieving the found posts.
  3251 			 * Filters the query to run for retrieving the found posts.
  3237 			 *
  3252 			 *
  3238 			 * @since 2.1.0
  3253 			 * @since 2.1.0
  3239 			 *
  3254 			 *
  3240 			 * @param string   $found_posts_query The query to run to find the found posts.
  3255 			 * @param string   $found_posts_query The query to run to find the found posts.
  3241 			 * @param WP_Query $this              The WP_Query instance (passed by reference).
  3256 			 * @param WP_Query $query             The WP_Query instance (passed by reference).
  3242 			 */
  3257 			 */
  3243 			$found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
  3258 			$found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
  3244 
  3259 
  3245 			$this->found_posts = (int) $wpdb->get_var( $found_posts_query );
  3260 			$this->found_posts = (int) $wpdb->get_var( $found_posts_query );
  3246 		} else {
  3261 		} else {
  3259 		 * Filters the number of found posts for the query.
  3274 		 * Filters the number of found posts for the query.
  3260 		 *
  3275 		 *
  3261 		 * @since 2.1.0
  3276 		 * @since 2.1.0
  3262 		 *
  3277 		 *
  3263 		 * @param int      $found_posts The number of posts found.
  3278 		 * @param int      $found_posts The number of posts found.
  3264 		 * @param WP_Query $this        The WP_Query instance (passed by reference).
  3279 		 * @param WP_Query $query       The WP_Query instance (passed by reference).
  3265 		 */
  3280 		 */
  3266 		$this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
  3281 		$this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
  3267 
  3282 
  3268 		if ( ! empty( $limits ) ) {
  3283 		if ( ! empty( $limits ) ) {
  3269 			$this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
  3284 			$this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
  3279 	 */
  3294 	 */
  3280 	public function next_post() {
  3295 	public function next_post() {
  3281 
  3296 
  3282 		$this->current_post++;
  3297 		$this->current_post++;
  3283 
  3298 
       
  3299 		/** @var WP_Post */
  3284 		$this->post = $this->posts[ $this->current_post ];
  3300 		$this->post = $this->posts[ $this->current_post ];
  3285 		return $this->post;
  3301 		return $this->post;
  3286 	}
  3302 	}
  3287 
  3303 
  3288 	/**
  3304 	/**
  3303 			/**
  3319 			/**
  3304 			 * Fires once the loop is started.
  3320 			 * Fires once the loop is started.
  3305 			 *
  3321 			 *
  3306 			 * @since 2.0.0
  3322 			 * @since 2.0.0
  3307 			 *
  3323 			 *
  3308 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  3324 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  3309 			 */
  3325 			 */
  3310 			do_action_ref_array( 'loop_start', array( &$this ) );
  3326 			do_action_ref_array( 'loop_start', array( &$this ) );
  3311 		}
  3327 		}
  3312 
  3328 
  3313 		$post = $this->next_post();
  3329 		$post = $this->next_post();
  3330 			/**
  3346 			/**
  3331 			 * Fires once the loop has ended.
  3347 			 * Fires once the loop has ended.
  3332 			 *
  3348 			 *
  3333 			 * @since 2.0.0
  3349 			 * @since 2.0.0
  3334 			 *
  3350 			 *
  3335 			 * @param WP_Query $this The WP_Query instance (passed by reference).
  3351 			 * @param WP_Query $query The WP_Query instance (passed by reference).
  3336 			 */
  3352 			 */
  3337 			do_action_ref_array( 'loop_end', array( &$this ) );
  3353 			do_action_ref_array( 'loop_end', array( &$this ) );
  3338 			// Do some cleaning up after the loop.
  3354 			// Do some cleaning up after the loop.
  3339 			$this->rewind_posts();
  3355 			$this->rewind_posts();
  3340 		} elseif ( 0 === $this->post_count ) {
  3356 		} elseif ( 0 === $this->post_count ) {
  3341 			/**
  3357 			/**
  3342 			 * Fires if no results are found in a post query.
  3358 			 * Fires if no results are found in a post query.
  3343 			 *
  3359 			 *
  3344 			 * @since 4.9.0
  3360 			 * @since 4.9.0
  3345 			 *
  3361 			 *
  3346 			 * @param WP_Query $this The WP_Query instance.
  3362 			 * @param WP_Query $query The WP_Query instance.
  3347 			 */
  3363 			 */
  3348 			do_action( 'loop_no_results', $this );
  3364 			do_action( 'loop_no_results', $this );
  3349 		}
  3365 		}
  3350 
  3366 
  3351 		$this->in_the_loop = false;
  3367 		$this->in_the_loop = false;
  3372 	 * @return WP_Comment Comment object.
  3388 	 * @return WP_Comment Comment object.
  3373 	 */
  3389 	 */
  3374 	public function next_comment() {
  3390 	public function next_comment() {
  3375 		$this->current_comment++;
  3391 		$this->current_comment++;
  3376 
  3392 
       
  3393 		/** @var WP_Comment */
  3377 		$this->comment = $this->comments[ $this->current_comment ];
  3394 		$this->comment = $this->comments[ $this->current_comment ];
  3378 		return $this->comment;
  3395 		return $this->comment;
  3379 	}
  3396 	}
  3380 
  3397 
  3381 	/**
  3398 	/**
  3447 		$this->query_vars = $this->query;
  3464 		$this->query_vars = $this->query;
  3448 		return $this->get_posts();
  3465 		return $this->get_posts();
  3449 	}
  3466 	}
  3450 
  3467 
  3451 	/**
  3468 	/**
  3452 	 * Retrieve queried object.
  3469 	 * Retrieves the currently queried object.
  3453 	 *
  3470 	 *
  3454 	 * If queried object is not set, then the queried object will be set from
  3471 	 * If queried object is not set, then the queried object will be set from
  3455 	 * the category, tag, taxonomy, posts page, single post, page, or author
  3472 	 * the category, tag, taxonomy, posts page, single post, page, or author
  3456 	 * query variable. After it is set up, it will be returned.
  3473 	 * query variable. After it is set up, it will be returned.
  3457 	 *
  3474 	 *
  3458 	 * @since 1.5.0
  3475 	 * @since 1.5.0
  3459 	 *
  3476 	 *
  3460 	 * @return object
  3477 	 * @return WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object.
  3461 	 */
  3478 	 */
  3462 	public function get_queried_object() {
  3479 	public function get_queried_object() {
  3463 		if ( isset( $this->queried_object ) ) {
  3480 		if ( isset( $this->queried_object ) ) {
  3464 			return $this->queried_object;
  3481 			return $this->queried_object;
  3465 		}
  3482 		}
  3525 
  3542 
  3526 		return $this->queried_object;
  3543 		return $this->queried_object;
  3527 	}
  3544 	}
  3528 
  3545 
  3529 	/**
  3546 	/**
  3530 	 * Retrieve ID of the current queried object.
  3547 	 * Retrieves the ID of the currently queried object.
  3531 	 *
  3548 	 *
  3532 	 * @since 1.5.0
  3549 	 * @since 1.5.0
  3533 	 *
  3550 	 *
  3534 	 * @return int
  3551 	 * @return int
  3535 	 */
  3552 	 */
  3605 	}
  3622 	}
  3606 
  3623 
  3607 	/**
  3624 	/**
  3608 	 * Is the query for an existing archive page?
  3625 	 * Is the query for an existing archive page?
  3609 	 *
  3626 	 *
  3610 	 * Month, Year, Category, Author, Post Type archive...
  3627 	 * Archive pages include category, tag, author, date, custom post type,
       
  3628 	 * and custom taxonomy based archives.
  3611 	 *
  3629 	 *
  3612 	 * @since 3.1.0
  3630 	 * @since 3.1.0
       
  3631 	 *
       
  3632 	 * @see WP_Query::is_category()
       
  3633 	 * @see WP_Query::is_tag()
       
  3634 	 * @see WP_Query::is_author()
       
  3635 	 * @see WP_Query::is_date()
       
  3636 	 * @see WP_Query::is_post_type_archive()
       
  3637 	 * @see WP_Query::is_tax()
  3613 	 *
  3638 	 *
  3614 	 * @return bool Whether the query is for an existing archive page.
  3639 	 * @return bool Whether the query is for an existing archive page.
  3615 	 */
  3640 	 */
  3616 	public function is_archive() {
  3641 	public function is_archive() {
  3617 		return (bool) $this->is_archive;
  3642 		return (bool) $this->is_archive;
  3942 	 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'.
  3967 	 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'.
  3943 	 *
  3968 	 *
  3944 	 * If you set a static page for the front page of your site, this function will return
  3969 	 * If you set a static page for the front page of your site, this function will return
  3945 	 * true only on the page you set as the "Posts page".
  3970 	 * true only on the page you set as the "Posts page".
  3946 	 *
  3971 	 *
       
  3972 	 * @since 3.1.0
       
  3973 	 *
  3947 	 * @see WP_Query::is_front_page()
  3974 	 * @see WP_Query::is_front_page()
  3948 	 *
       
  3949 	 * @since 3.1.0
       
  3950 	 *
  3975 	 *
  3951 	 * @return bool Whether the query is for the blog homepage.
  3976 	 * @return bool Whether the query is for the blog homepage.
  3952 	 */
  3977 	 */
  3953 	public function is_home() {
  3978 	public function is_home() {
  3954 		return (bool) $this->is_home;
  3979 		return (bool) $this->is_home;
  3992 	 * Is the query for an existing single page?
  4017 	 * Is the query for an existing single page?
  3993 	 *
  4018 	 *
  3994 	 * If the $page parameter is specified, this function will additionally
  4019 	 * If the $page parameter is specified, this function will additionally
  3995 	 * check if the query is for one of the pages specified.
  4020 	 * check if the query is for one of the pages specified.
  3996 	 *
  4021 	 *
       
  4022 	 * @since 3.1.0
       
  4023 	 *
  3997 	 * @see WP_Query::is_single()
  4024 	 * @see WP_Query::is_single()
  3998 	 * @see WP_Query::is_singular()
  4025 	 * @see WP_Query::is_singular()
  3999 	 *
       
  4000 	 * @since 3.1.0
       
  4001 	 *
  4026 	 *
  4002 	 * @param int|string|int[]|string[] $page Optional. Page ID, title, slug, path, or array of such
  4027 	 * @param int|string|int[]|string[] $page Optional. Page ID, title, slug, path, or array of such
  4003 	 *                                        to check against. Default empty.
  4028 	 *                                        to check against. Default empty.
  4004 	 * @return bool Whether the query is for an existing single page.
  4029 	 * @return bool Whether the query is for an existing single page.
  4005 	 */
  4030 	 */
  4099 	 * Works for any post type excluding pages.
  4124 	 * Works for any post type excluding pages.
  4100 	 *
  4125 	 *
  4101 	 * If the $post parameter is specified, this function will additionally
  4126 	 * If the $post parameter is specified, this function will additionally
  4102 	 * check if the query is for one of the Posts specified.
  4127 	 * check if the query is for one of the Posts specified.
  4103 	 *
  4128 	 *
       
  4129 	 * @since 3.1.0
       
  4130 	 *
  4104 	 * @see WP_Query::is_page()
  4131 	 * @see WP_Query::is_page()
  4105 	 * @see WP_Query::is_singular()
  4132 	 * @see WP_Query::is_singular()
  4106 	 *
       
  4107 	 * @since 3.1.0
       
  4108 	 *
  4133 	 *
  4109 	 * @param int|string|int[]|string[] $post Optional. Post ID, title, slug, path, or array of such
  4134 	 * @param int|string|int[]|string[] $post Optional. Post ID, title, slug, path, or array of such
  4110 	 *                                        to check against. Default empty.
  4135 	 *                                        to check against. Default empty.
  4111 	 * @return bool Whether the query is for an existing single post.
  4136 	 * @return bool Whether the query is for an existing single post.
  4112 	 */
  4137 	 */
  4149 	 * custom post types)?
  4174 	 * custom post types)?
  4150 	 *
  4175 	 *
  4151 	 * If the $post_types parameter is specified, this function will additionally
  4176 	 * If the $post_types parameter is specified, this function will additionally
  4152 	 * check if the query is for one of the Posts Types specified.
  4177 	 * check if the query is for one of the Posts Types specified.
  4153 	 *
  4178 	 *
       
  4179 	 * @since 3.1.0
       
  4180 	 *
  4154 	 * @see WP_Query::is_page()
  4181 	 * @see WP_Query::is_page()
  4155 	 * @see WP_Query::is_single()
  4182 	 * @see WP_Query::is_single()
  4156 	 *
       
  4157 	 * @since 3.1.0
       
  4158 	 *
  4183 	 *
  4159 	 * @param string|string[] $post_types Optional. Post type or array of post types
  4184 	 * @param string|string[] $post_types Optional. Post type or array of post types
  4160 	 *                                    to check against. Default empty.
  4185 	 *                                    to check against. Default empty.
  4161 	 * @return bool Whether the query is for an existing single post
  4186 	 * @return bool Whether the query is for an existing single post
  4162 	 *              or any of the given post types.
  4187 	 *              or any of the given post types.
  4287 
  4312 
  4288 		/**
  4313 		/**
  4289 		 * Fires once the post data has been set up.
  4314 		 * Fires once the post data has been set up.
  4290 		 *
  4315 		 *
  4291 		 * @since 2.8.0
  4316 		 * @since 2.8.0
  4292 		 * @since 4.1.0 Introduced `$this` parameter.
  4317 		 * @since 4.1.0 Introduced `$query` parameter.
  4293 		 *
  4318 		 *
  4294 		 * @param WP_Post  $post The Post object (passed by reference).
  4319 		 * @param WP_Post  $post  The Post object (passed by reference).
  4295 		 * @param WP_Query $this The current Query object (passed by reference).
  4320 		 * @param WP_Query $query The current Query object (passed by reference).
  4296 		 */
  4321 		 */
  4297 		do_action_ref_array( 'the_post', array( &$post, &$this ) );
  4322 		do_action_ref_array( 'the_post', array( &$post, &$this ) );
  4298 
  4323 
  4299 		return true;
  4324 		return true;
  4300 	}
  4325 	}
  4303 	 * Generate post data.
  4328 	 * Generate post data.
  4304 	 *
  4329 	 *
  4305 	 * @since 5.2.0
  4330 	 * @since 5.2.0
  4306 	 *
  4331 	 *
  4307 	 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
  4332 	 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
  4308 	 * @return array|bool Elements of post or false on failure.
  4333 	 * @return array|false Elements of post or false on failure.
  4309 	 */
  4334 	 */
  4310 	public function generate_postdata( $post ) {
  4335 	public function generate_postdata( $post ) {
  4311 
  4336 
  4312 		if ( ! ( $post instanceof WP_Post ) ) {
  4337 		if ( ! ( $post instanceof WP_Post ) ) {
  4313 			$post = get_post( $post );
  4338 			$post = get_post( $post );