rebase on oct-10-2023
This commit is contained in:
@@ -108,6 +108,14 @@ class WP_Query {
|
||||
*/
|
||||
public $current_post = -1;
|
||||
|
||||
/**
|
||||
* Whether the caller is before the loop.
|
||||
*
|
||||
* @since 6.3.0
|
||||
* @var bool
|
||||
*/
|
||||
public $before_loop = true;
|
||||
|
||||
/**
|
||||
* Whether the loop has started and the caller is in the loop.
|
||||
*
|
||||
@@ -517,6 +525,7 @@ class WP_Query {
|
||||
$this->post_count = 0;
|
||||
$this->current_post = -1;
|
||||
$this->in_the_loop = false;
|
||||
$this->before_loop = true;
|
||||
unset( $this->request );
|
||||
unset( $this->post );
|
||||
unset( $this->comments );
|
||||
@@ -531,7 +540,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reparse the query vars.
|
||||
* Reparses the query vars.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@@ -623,7 +632,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a query string and set query type booleans.
|
||||
* Parses a query string and sets query type booleans.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's
|
||||
@@ -643,140 +652,140 @@ class WP_Query {
|
||||
* @param string|array $query {
|
||||
* Optional. Array or string of Query parameters.
|
||||
*
|
||||
* @type int $attachment_id Attachment post ID. Used for 'attachment' post_type.
|
||||
* @type int|string $author Author ID, or comma-separated list of IDs.
|
||||
* @type string $author_name User 'user_nicename'.
|
||||
* @type int[] $author__in An array of author IDs to query from.
|
||||
* @type int[] $author__not_in An array of author IDs not to query from.
|
||||
* @type bool $cache_results Whether to cache post information. Default true.
|
||||
* @type int|string $cat Category ID or comma-separated list of IDs (this or any children).
|
||||
* @type int[] $category__and An array of category IDs (AND in).
|
||||
* @type int[] $category__in An array of category IDs (OR in, no children).
|
||||
* @type int[] $category__not_in An array of category IDs (NOT in).
|
||||
* @type string $category_name Use category slug (not name, this or any children).
|
||||
* @type array|int $comment_count Filter results by comment count. Provide an integer to match
|
||||
* comment count exactly. Provide an array with integer 'value'
|
||||
* and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
|
||||
* compare against comment_count in a specific way.
|
||||
* @type string $comment_status Comment status.
|
||||
* @type int $comments_per_page The number of comments to return per page.
|
||||
* Default 'comments_per_page' option.
|
||||
* @type array $date_query An associative array of WP_Date_Query arguments.
|
||||
* See WP_Date_Query::__construct().
|
||||
* @type int $day Day of the month. Default empty. Accepts numbers 1-31.
|
||||
* @type bool $exact Whether to search by exact keyword. Default false.
|
||||
* @type string $fields Post fields to query for. Accepts:
|
||||
* - '' Returns an array of complete post objects (`WP_Post[]`).
|
||||
* - 'ids' Returns an array of post IDs (`int[]`).
|
||||
* - 'id=>parent' Returns an associative array of parent post IDs,
|
||||
* keyed by post ID (`int[]`).
|
||||
* Default ''.
|
||||
* @type int $hour Hour of the day. Default empty. Accepts numbers 0-23.
|
||||
* @type int|bool $ignore_sticky_posts Whether to ignore sticky posts or not. Setting this to false
|
||||
* excludes stickies from 'post__in'. Accepts 1|true, 0|false.
|
||||
* Default false.
|
||||
* @type int $m Combination YearMonth. Accepts any four-digit year and month
|
||||
* numbers 01-12. Default empty.
|
||||
* @type string|string[] $meta_key Meta key or keys to filter by.
|
||||
* @type string|string[] $meta_value Meta value or values to filter by.
|
||||
* @type string $meta_compare MySQL operator used for comparing the meta value.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type string $meta_compare_key MySQL operator used for comparing the meta key.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type string $meta_type MySQL data type that the meta_value column will be CAST to for comparisons.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type string $meta_type_key MySQL data type that the meta_key column will be CAST to for comparisons.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type array $meta_query An associative array of WP_Meta_Query arguments.
|
||||
* See WP_Meta_Query::__construct() for accepted values.
|
||||
* @type int $menu_order The menu order of the posts.
|
||||
* @type int $minute Minute of the hour. Default empty. Accepts numbers 0-59.
|
||||
* @type int $monthnum The two-digit month. Default empty. Accepts numbers 1-12.
|
||||
* @type string $name Post slug.
|
||||
* @type bool $nopaging Show all posts (true) or paginate (false). Default false.
|
||||
* @type bool $no_found_rows Whether to skip counting the total rows found. Enabling can improve
|
||||
* performance. Default false.
|
||||
* @type int $offset The number of posts to offset before retrieval.
|
||||
* @type string $order Designates ascending or descending order of posts. Default 'DESC'.
|
||||
* Accepts 'ASC', 'DESC'.
|
||||
* @type string|array $orderby Sort retrieved posts by parameter. One or more options may be passed.
|
||||
* To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be
|
||||
* also be defined. To sort by a specific `$meta_query` clause, use that
|
||||
* clause's array key. Accepts:
|
||||
* - 'none'
|
||||
* - 'name'
|
||||
* - 'author'
|
||||
* - 'date'
|
||||
* - 'title'
|
||||
* - 'modified'
|
||||
* - 'menu_order'
|
||||
* - 'parent'
|
||||
* - 'ID'
|
||||
* - 'rand'
|
||||
* - 'relevance'
|
||||
* - 'RAND(x)' (where 'x' is an integer seed value)
|
||||
* - 'comment_count'
|
||||
* - 'meta_value'
|
||||
* - 'meta_value_num'
|
||||
* - 'post__in'
|
||||
* - 'post_name__in'
|
||||
* - 'post_parent__in'
|
||||
* - The array keys of `$meta_query`.
|
||||
* Default is 'date', except when a search is being performed, when
|
||||
* the default is 'relevance'.
|
||||
* @type int $p Post ID.
|
||||
* @type int $page Show the number of posts that would show up on page X of a
|
||||
* static front page.
|
||||
* @type int $paged The number of the current page.
|
||||
* @type int $page_id Page ID.
|
||||
* @type string $pagename Page slug.
|
||||
* @type string $perm Show posts if user has the appropriate capability.
|
||||
* @type string $ping_status Ping status.
|
||||
* @type int[] $post__in An array of post IDs to retrieve, sticky posts will be included.
|
||||
* @type int[] $post__not_in An array of post IDs not to retrieve. Note: a string of comma-
|
||||
* separated IDs will NOT work.
|
||||
* @type string $post_mime_type The mime type of the post. Used for 'attachment' post_type.
|
||||
* @type string[] $post_name__in An array of post slugs that results must match.
|
||||
* @type int $post_parent Page ID to retrieve child pages for. Use 0 to only retrieve
|
||||
* top-level pages.
|
||||
* @type int[] $post_parent__in An array containing parent page IDs to query child pages from.
|
||||
* @type int[] $post_parent__not_in An array containing parent page IDs not to query child pages from.
|
||||
* @type string|string[] $post_type A post type slug (string) or array of post type slugs.
|
||||
* Default 'any' if using 'tax_query'.
|
||||
* @type string|string[] $post_status A post status (string) or array of post statuses.
|
||||
* @type int $posts_per_page The number of posts to query for. Use -1 to request all posts.
|
||||
* @type int $posts_per_archive_page The number of posts to query for by archive page. Overrides
|
||||
* 'posts_per_page' when is_archive(), or is_search() are true.
|
||||
* @type string $s Search keyword(s). Prepending a term with a hyphen will
|
||||
* exclude posts matching that term. Eg, 'pillow -sofa' will
|
||||
* return posts containing 'pillow' but not 'sofa'. The
|
||||
* character used for exclusion can be modified using the
|
||||
* the 'wp_query_search_exclusion_prefix' filter.
|
||||
* @type string[] $search_columns Array of column names to be searched. Accepts 'post_title',
|
||||
* 'post_excerpt' and 'post_content'. Default empty array.
|
||||
* @type int $second Second of the minute. Default empty. Accepts numbers 0-59.
|
||||
* @type bool $sentence Whether to search by phrase. Default false.
|
||||
* @type bool $suppress_filters Whether to suppress filters. Default false.
|
||||
* @type string $tag Tag slug. Comma-separated (either), Plus-separated (all).
|
||||
* @type int[] $tag__and An array of tag IDs (AND in).
|
||||
* @type int[] $tag__in An array of tag IDs (OR in).
|
||||
* @type int[] $tag__not_in An array of tag IDs (NOT in).
|
||||
* @type int $tag_id Tag id or comma-separated list of IDs.
|
||||
* @type string[] $tag_slug__and An array of tag slugs (AND in).
|
||||
* @type string[] $tag_slug__in An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
|
||||
* true. Note: a string of comma-separated IDs will NOT work.
|
||||
* @type array $tax_query An associative array of WP_Tax_Query arguments.
|
||||
* See WP_Tax_Query::__construct().
|
||||
* @type string $title Post title.
|
||||
* @type bool $update_post_meta_cache Whether to update the post meta cache. Default true.
|
||||
* @type bool $update_post_term_cache Whether to update the post term cache. Default true.
|
||||
* @type bool $update_menu_item_cache Whether to update the menu item cache. Default false.
|
||||
* @type bool $lazy_load_term_meta Whether to lazy-load term meta. Setting to false will
|
||||
* disable cache priming for term meta, so that each
|
||||
* get_term_meta() call will hit the database.
|
||||
* Defaults to the value of `$update_post_term_cache`.
|
||||
* @type int $w The week number of the year. Default empty. Accepts numbers 0-53.
|
||||
* @type int $year The four-digit year. Default empty. Accepts any four-digit year.
|
||||
* @type int $attachment_id Attachment post ID. Used for 'attachment' post_type.
|
||||
* @type int|string $author Author ID, or comma-separated list of IDs.
|
||||
* @type string $author_name User 'user_nicename'.
|
||||
* @type int[] $author__in An array of author IDs to query from.
|
||||
* @type int[] $author__not_in An array of author IDs not to query from.
|
||||
* @type bool $cache_results Whether to cache post information. Default true.
|
||||
* @type int|string $cat Category ID or comma-separated list of IDs (this or any children).
|
||||
* @type int[] $category__and An array of category IDs (AND in).
|
||||
* @type int[] $category__in An array of category IDs (OR in, no children).
|
||||
* @type int[] $category__not_in An array of category IDs (NOT in).
|
||||
* @type string $category_name Use category slug (not name, this or any children).
|
||||
* @type array|int $comment_count Filter results by comment count. Provide an integer to match
|
||||
* comment count exactly. Provide an array with integer 'value'
|
||||
* and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
|
||||
* compare against comment_count in a specific way.
|
||||
* @type string $comment_status Comment status.
|
||||
* @type int $comments_per_page The number of comments to return per page.
|
||||
* Default 'comments_per_page' option.
|
||||
* @type array $date_query An associative array of WP_Date_Query arguments.
|
||||
* See WP_Date_Query::__construct().
|
||||
* @type int $day Day of the month. Default empty. Accepts numbers 1-31.
|
||||
* @type bool $exact Whether to search by exact keyword. Default false.
|
||||
* @type string $fields Post fields to query for. Accepts:
|
||||
* - '' Returns an array of complete post objects (`WP_Post[]`).
|
||||
* - 'ids' Returns an array of post IDs (`int[]`).
|
||||
* - 'id=>parent' Returns an associative array of parent post IDs,
|
||||
* keyed by post ID (`int[]`).
|
||||
* Default ''.
|
||||
* @type int $hour Hour of the day. Default empty. Accepts numbers 0-23.
|
||||
* @type int|bool $ignore_sticky_posts Whether to ignore sticky posts or not. Setting this to false
|
||||
* excludes stickies from 'post__in'. Accepts 1|true, 0|false.
|
||||
* Default false.
|
||||
* @type int $m Combination YearMonth. Accepts any four-digit year and month
|
||||
* numbers 01-12. Default empty.
|
||||
* @type string|string[] $meta_key Meta key or keys to filter by.
|
||||
* @type string|string[] $meta_value Meta value or values to filter by.
|
||||
* @type string $meta_compare MySQL operator used for comparing the meta value.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type string $meta_compare_key MySQL operator used for comparing the meta key.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type string $meta_type MySQL data type that the meta_value column will be CAST to for comparisons.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type string $meta_type_key MySQL data type that the meta_key column will be CAST to for comparisons.
|
||||
* See WP_Meta_Query::__construct() for accepted values and default value.
|
||||
* @type array $meta_query An associative array of WP_Meta_Query arguments.
|
||||
* See WP_Meta_Query::__construct() for accepted values.
|
||||
* @type int $menu_order The menu order of the posts.
|
||||
* @type int $minute Minute of the hour. Default empty. Accepts numbers 0-59.
|
||||
* @type int $monthnum The two-digit month. Default empty. Accepts numbers 1-12.
|
||||
* @type string $name Post slug.
|
||||
* @type bool $nopaging Show all posts (true) or paginate (false). Default false.
|
||||
* @type bool $no_found_rows Whether to skip counting the total rows found. Enabling can improve
|
||||
* performance. Default false.
|
||||
* @type int $offset The number of posts to offset before retrieval.
|
||||
* @type string $order Designates ascending or descending order of posts. Default 'DESC'.
|
||||
* Accepts 'ASC', 'DESC'.
|
||||
* @type string|array $orderby Sort retrieved posts by parameter. One or more options may be passed.
|
||||
* To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be
|
||||
* also be defined. To sort by a specific `$meta_query` clause, use that
|
||||
* clause's array key. Accepts:
|
||||
* - 'none'
|
||||
* - 'name'
|
||||
* - 'author'
|
||||
* - 'date'
|
||||
* - 'title'
|
||||
* - 'modified'
|
||||
* - 'menu_order'
|
||||
* - 'parent'
|
||||
* - 'ID'
|
||||
* - 'rand'
|
||||
* - 'relevance'
|
||||
* - 'RAND(x)' (where 'x' is an integer seed value)
|
||||
* - 'comment_count'
|
||||
* - 'meta_value'
|
||||
* - 'meta_value_num'
|
||||
* - 'post__in'
|
||||
* - 'post_name__in'
|
||||
* - 'post_parent__in'
|
||||
* - The array keys of `$meta_query`.
|
||||
* Default is 'date', except when a search is being performed, when
|
||||
* the default is 'relevance'.
|
||||
* @type int $p Post ID.
|
||||
* @type int $page Show the number of posts that would show up on page X of a
|
||||
* static front page.
|
||||
* @type int $paged The number of the current page.
|
||||
* @type int $page_id Page ID.
|
||||
* @type string $pagename Page slug.
|
||||
* @type string $perm Show posts if user has the appropriate capability.
|
||||
* @type string $ping_status Ping status.
|
||||
* @type int[] $post__in An array of post IDs to retrieve, sticky posts will be included.
|
||||
* @type int[] $post__not_in An array of post IDs not to retrieve. Note: a string of comma-
|
||||
* separated IDs will NOT work.
|
||||
* @type string $post_mime_type The mime type of the post. Used for 'attachment' post_type.
|
||||
* @type string[] $post_name__in An array of post slugs that results must match.
|
||||
* @type int $post_parent Page ID to retrieve child pages for. Use 0 to only retrieve
|
||||
* top-level pages.
|
||||
* @type int[] $post_parent__in An array containing parent page IDs to query child pages from.
|
||||
* @type int[] $post_parent__not_in An array containing parent page IDs not to query child pages from.
|
||||
* @type string|string[] $post_type A post type slug (string) or array of post type slugs.
|
||||
* Default 'any' if using 'tax_query'.
|
||||
* @type string|string[] $post_status A post status (string) or array of post statuses.
|
||||
* @type int $posts_per_page The number of posts to query for. Use -1 to request all posts.
|
||||
* @type int $posts_per_archive_page The number of posts to query for by archive page. Overrides
|
||||
* 'posts_per_page' when is_archive(), or is_search() are true.
|
||||
* @type string $s Search keyword(s). Prepending a term with a hyphen will
|
||||
* exclude posts matching that term. Eg, 'pillow -sofa' will
|
||||
* return posts containing 'pillow' but not 'sofa'. The
|
||||
* character used for exclusion can be modified using the
|
||||
* the 'wp_query_search_exclusion_prefix' filter.
|
||||
* @type string[] $search_columns Array of column names to be searched. Accepts 'post_title',
|
||||
* 'post_excerpt' and 'post_content'. Default empty array.
|
||||
* @type int $second Second of the minute. Default empty. Accepts numbers 0-59.
|
||||
* @type bool $sentence Whether to search by phrase. Default false.
|
||||
* @type bool $suppress_filters Whether to suppress filters. Default false.
|
||||
* @type string $tag Tag slug. Comma-separated (either), Plus-separated (all).
|
||||
* @type int[] $tag__and An array of tag IDs (AND in).
|
||||
* @type int[] $tag__in An array of tag IDs (OR in).
|
||||
* @type int[] $tag__not_in An array of tag IDs (NOT in).
|
||||
* @type int $tag_id Tag id or comma-separated list of IDs.
|
||||
* @type string[] $tag_slug__and An array of tag slugs (AND in).
|
||||
* @type string[] $tag_slug__in An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
|
||||
* true. Note: a string of comma-separated IDs will NOT work.
|
||||
* @type array $tax_query An associative array of WP_Tax_Query arguments.
|
||||
* See WP_Tax_Query::__construct().
|
||||
* @type string $title Post title.
|
||||
* @type bool $update_post_meta_cache Whether to update the post meta cache. Default true.
|
||||
* @type bool $update_post_term_cache Whether to update the post term cache. Default true.
|
||||
* @type bool $update_menu_item_cache Whether to update the menu item cache. Default false.
|
||||
* @type bool $lazy_load_term_meta Whether to lazy-load term meta. Setting to false will
|
||||
* disable cache priming for term meta, so that each
|
||||
* get_term_meta() call will hit the database.
|
||||
* Defaults to the value of `$update_post_term_cache`.
|
||||
* @type int $w The week number of the year. Default empty. Accepts numbers 0-53.
|
||||
* @type int $year The four-digit year. Default empty. Accepts any four-digit year.
|
||||
* }
|
||||
*/
|
||||
public function parse_query( $query = '' ) {
|
||||
@@ -1006,7 +1015,7 @@ class WP_Query {
|
||||
$this->is_admin = true;
|
||||
}
|
||||
|
||||
if ( false !== strpos( $qv['feed'], 'comments-' ) ) {
|
||||
if ( str_contains( $qv['feed'], 'comments-' ) ) {
|
||||
$qv['feed'] = str_replace( 'comments-', '', $qv['feed'] );
|
||||
$qv['withcomments'] = 1;
|
||||
}
|
||||
@@ -1176,7 +1185,7 @@ class WP_Query {
|
||||
$term = implode( ',', $term );
|
||||
}
|
||||
|
||||
if ( strpos( $term, '+' ) !== false ) {
|
||||
if ( str_contains( $term, '+' ) ) {
|
||||
$terms = preg_split( '/[+]+/', $term );
|
||||
foreach ( $terms as $term ) {
|
||||
$tax_query[] = array_merge(
|
||||
@@ -1289,7 +1298,7 @@ class WP_Query {
|
||||
// Tag stuff.
|
||||
|
||||
if ( '' !== $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
|
||||
if ( strpos( $q['tag'], ',' ) !== false ) {
|
||||
if ( str_contains( $q['tag'], ',' ) ) {
|
||||
$tags = preg_split( '/[,\r\n\t ]+/', $q['tag'] );
|
||||
foreach ( (array) $tags as $tag ) {
|
||||
$tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' );
|
||||
@@ -1452,7 +1461,7 @@ class WP_Query {
|
||||
|
||||
foreach ( $q['search_terms'] as $term ) {
|
||||
// If there is an $exclusion_prefix, terms prefixed with it should be excluded.
|
||||
$exclude = $exclusion_prefix && ( substr( $term, 0, 1 ) === $exclusion_prefix );
|
||||
$exclude = $exclusion_prefix && str_starts_with( $term, $exclusion_prefix );
|
||||
if ( $exclude ) {
|
||||
$like_op = 'NOT LIKE';
|
||||
$andor_op = 'AND';
|
||||
@@ -1494,7 +1503,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the terms are suitable for searching.
|
||||
* Checks if the terms are suitable for searching.
|
||||
*
|
||||
* Uses an array of stopwords (terms) that are excluded from the separate
|
||||
* term matching when searching for posts. The list of English stopwords is
|
||||
@@ -1535,7 +1544,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve stopwords used when parsing search terms.
|
||||
* Retrieves stopwords used when parsing search terms.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
@@ -1607,8 +1616,10 @@ class WP_Query {
|
||||
$search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like );
|
||||
}
|
||||
|
||||
// Sanity limit, sort as sentence when more than 6 terms
|
||||
// (few searches are longer than 6 terms and most titles are not).
|
||||
/*
|
||||
* Sanity limit, sort as sentence when more than 6 terms
|
||||
* (few searches are longer than 6 terms and most titles are not).
|
||||
*/
|
||||
if ( $num_terms < 7 ) {
|
||||
// All words in title.
|
||||
$search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 ';
|
||||
@@ -2252,7 +2263,7 @@ class WP_Query {
|
||||
}
|
||||
if ( ! $post_type ) {
|
||||
$post_type = 'any';
|
||||
} elseif ( count( $post_type ) == 1 ) {
|
||||
} elseif ( count( $post_type ) === 1 ) {
|
||||
$post_type = $post_type[0];
|
||||
}
|
||||
|
||||
@@ -2345,7 +2356,7 @@ class WP_Query {
|
||||
// Author stuff for nice URLs.
|
||||
|
||||
if ( '' !== $q['author_name'] ) {
|
||||
if ( strpos( $q['author_name'], '/' ) !== false ) {
|
||||
if ( str_contains( $q['author_name'], '/' ) ) {
|
||||
$q['author_name'] = explode( '/', $q['author_name'] );
|
||||
if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) {
|
||||
$q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash.
|
||||
@@ -2808,12 +2819,12 @@ class WP_Query {
|
||||
$last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );
|
||||
|
||||
$cache_key = "comment_feed:$key:$last_changed";
|
||||
$comment_ids = wp_cache_get( $cache_key, 'comment' );
|
||||
$comment_ids = wp_cache_get( $cache_key, 'comment-queries' );
|
||||
if ( false === $comment_ids ) {
|
||||
$comment_ids = $wpdb->get_col( $comments_request );
|
||||
wp_cache_add( $cache_key, $comment_ids, 'comment' );
|
||||
wp_cache_add( $cache_key, $comment_ids, 'comment-queries' );
|
||||
}
|
||||
_prime_comment_caches( $comment_ids, false );
|
||||
_prime_comment_caches( $comment_ids );
|
||||
|
||||
// Convert to WP_Comment.
|
||||
/** @var WP_Comment[] */
|
||||
@@ -3165,7 +3176,7 @@ class WP_Query {
|
||||
|
||||
$cache_found = false;
|
||||
if ( null === $this->posts ) {
|
||||
$cached_results = wp_cache_get( $cache_key, 'posts', false, $cache_found );
|
||||
$cached_results = wp_cache_get( $cache_key, 'post-queries', false, $cache_found );
|
||||
|
||||
if ( $cached_results ) {
|
||||
if ( 'ids' === $q['fields'] ) {
|
||||
@@ -3220,7 +3231,7 @@ class WP_Query {
|
||||
'max_num_pages' => $this->max_num_pages,
|
||||
);
|
||||
|
||||
wp_cache_set( $cache_key, $cache_value, 'posts' );
|
||||
wp_cache_set( $cache_key, $cache_value, 'post-queries' );
|
||||
}
|
||||
|
||||
return $this->posts;
|
||||
@@ -3253,7 +3264,7 @@ class WP_Query {
|
||||
'max_num_pages' => $this->max_num_pages,
|
||||
);
|
||||
|
||||
wp_cache_set( $cache_key, $cache_value, 'posts' );
|
||||
wp_cache_set( $cache_key, $cache_value, 'post-queries' );
|
||||
}
|
||||
|
||||
return $post_parents;
|
||||
@@ -3328,7 +3339,7 @@ class WP_Query {
|
||||
'max_num_pages' => $this->max_num_pages,
|
||||
);
|
||||
|
||||
wp_cache_set( $cache_key, $cache_value, 'posts' );
|
||||
wp_cache_set( $cache_key, $cache_value, 'post-queries' );
|
||||
}
|
||||
|
||||
if ( ! $q['suppress_filters'] ) {
|
||||
@@ -3367,12 +3378,12 @@ class WP_Query {
|
||||
$comment_last_changed = wp_cache_get_last_changed( 'comment' );
|
||||
|
||||
$comment_cache_key = "comment_feed:$comment_key:$comment_last_changed";
|
||||
$comment_ids = wp_cache_get( $comment_cache_key, 'comment' );
|
||||
$comment_ids = wp_cache_get( $comment_cache_key, 'comment-queries' );
|
||||
if ( false === $comment_ids ) {
|
||||
$comment_ids = $wpdb->get_col( $comments_request );
|
||||
wp_cache_add( $comment_cache_key, $comment_ids, 'comment' );
|
||||
wp_cache_add( $comment_cache_key, $comment_ids, 'comment-queries' );
|
||||
}
|
||||
_prime_comment_caches( $comment_ids, false );
|
||||
_prime_comment_caches( $comment_ids );
|
||||
|
||||
// Convert to WP_Comment.
|
||||
/** @var WP_Comment[] */
|
||||
@@ -3487,11 +3498,6 @@ class WP_Query {
|
||||
}
|
||||
}
|
||||
|
||||
// If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up.
|
||||
if ( ! empty( $this->comments ) ) {
|
||||
wp_queue_comments_for_comment_meta_lazyload( $this->comments );
|
||||
}
|
||||
|
||||
if ( ! $q['suppress_filters'] ) {
|
||||
/**
|
||||
* Filters the array of retrieved posts after they've been fetched and
|
||||
@@ -3505,8 +3511,10 @@ class WP_Query {
|
||||
$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );
|
||||
}
|
||||
|
||||
// Ensure that any posts added/modified via one of the filters above are
|
||||
// of the type WP_Post and are filtered.
|
||||
/*
|
||||
* Ensure that any posts added/modified via one of the filters above are
|
||||
* of the type WP_Post and are filtered.
|
||||
*/
|
||||
if ( $this->posts ) {
|
||||
$this->post_count = count( $this->posts );
|
||||
|
||||
@@ -3536,7 +3544,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the amount of found posts and the number of pages (if limit clause was used)
|
||||
* Sets up the amount of found posts and the number of pages (if limit clause was used)
|
||||
* for the current query.
|
||||
*
|
||||
* @since 3.5.0
|
||||
@@ -3549,8 +3557,10 @@ class WP_Query {
|
||||
private function set_found_posts( $q, $limits ) {
|
||||
global $wpdb;
|
||||
|
||||
// Bail if posts is an empty array. Continue if posts is an empty string,
|
||||
// null, or false to accommodate caching plugins that fill posts later.
|
||||
/*
|
||||
* Bail if posts is an empty array. Continue if posts is an empty string,
|
||||
* null, or false to accommodate caching plugins that fill posts later.
|
||||
*/
|
||||
if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) {
|
||||
return;
|
||||
}
|
||||
@@ -3595,7 +3605,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the next post and iterate current post index.
|
||||
* Sets up the next post and iterate current post index.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
@@ -3636,6 +3646,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$this->in_the_loop = true;
|
||||
$this->before_loop = false;
|
||||
|
||||
if ( -1 == $this->current_post ) { // Loop has just started.
|
||||
/**
|
||||
@@ -3676,6 +3687,8 @@ class WP_Query {
|
||||
// Do some cleaning up after the loop.
|
||||
$this->rewind_posts();
|
||||
} elseif ( 0 === $this->post_count ) {
|
||||
$this->before_loop = false;
|
||||
|
||||
/**
|
||||
* Fires if no results are found in a post query.
|
||||
*
|
||||
@@ -3691,7 +3704,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the posts and reset post index.
|
||||
* Rewinds the posts and resets post index.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@@ -3703,7 +3716,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate current comment index and return WP_Comment object.
|
||||
* Iterates current comment index and returns WP_Comment object.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
@@ -3740,7 +3753,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether there are more comments available.
|
||||
* Determines whether there are more comments available.
|
||||
*
|
||||
* Automatically rewinds comments when finished.
|
||||
*
|
||||
@@ -3759,7 +3772,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the comments, resets the comment index and comment to first.
|
||||
* Rewinds the comments, resets the comment index and comment to first.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@@ -3921,7 +3934,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private properties readable for backward compatibility.
|
||||
* Makes private properties readable for backward compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
@@ -3935,7 +3948,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private properties checkable for backward compatibility.
|
||||
* Makes private properties checkable for backward compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
@@ -3949,7 +3962,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private/protected methods readable for backward compatibility.
|
||||
* Makes private/protected methods readable for backward compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
@@ -3965,7 +3978,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing archive page?
|
||||
* Determines whether the query is for an existing archive page.
|
||||
*
|
||||
* Archive pages include category, tag, author, date, custom post type,
|
||||
* and custom taxonomy based archives.
|
||||
@@ -3986,7 +3999,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing post type archive page?
|
||||
* Determines whether the query is for an existing post type archive page.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4013,7 +4026,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing attachment page?
|
||||
* Determines whether the query is for an existing attachment page.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4048,7 +4061,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing author archive page?
|
||||
* Determines whether the query is for an existing author archive page.
|
||||
*
|
||||
* If the $author parameter is specified, this function will additionally
|
||||
* check if the query is for one of the authors specified.
|
||||
@@ -4087,7 +4100,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing category archive page?
|
||||
* Determines whether the query is for an existing category archive page.
|
||||
*
|
||||
* If the $category parameter is specified, this function will additionally
|
||||
* check if the query is for one of the categories specified.
|
||||
@@ -4126,7 +4139,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing tag archive page?
|
||||
* Determines whether the query is for an existing tag archive page.
|
||||
*
|
||||
* If the $tag parameter is specified, this function will additionally
|
||||
* check if the query is for one of the tags specified.
|
||||
@@ -4165,7 +4178,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing custom taxonomy archive page?
|
||||
* Determines whether the query is for an existing custom taxonomy archive page.
|
||||
*
|
||||
* If the $taxonomy parameter is specified, this function will additionally
|
||||
* check if the query is for that specific $taxonomy.
|
||||
@@ -4221,7 +4234,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the current URL is within the comments popup window.
|
||||
* Determines whether the current URL is within the comments popup window.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @deprecated 4.5.0
|
||||
@@ -4235,7 +4248,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing date archive?
|
||||
* Determines whether the query is for an existing date archive.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4246,7 +4259,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing day archive?
|
||||
* Determines whether the query is for an existing day archive.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4257,7 +4270,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a feed?
|
||||
* Determines whether the query is for a feed.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4279,7 +4292,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a comments feed?
|
||||
* Determines whether the query is for a comments feed.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4290,7 +4303,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for the front page of the site?
|
||||
* Determines whether the query is for the front page of the site.
|
||||
*
|
||||
* This is for what is displayed at your site's main URL.
|
||||
*
|
||||
@@ -4319,7 +4332,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for the blog homepage?
|
||||
* Determines whether the query is for the blog homepage.
|
||||
*
|
||||
* This is the page which shows the time based blog content of your site.
|
||||
*
|
||||
@@ -4339,7 +4352,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for the Privacy Policy page?
|
||||
* Determines whether the query is for the Privacy Policy page.
|
||||
*
|
||||
* This is the page which shows the Privacy Policy content of your site.
|
||||
*
|
||||
@@ -4362,7 +4375,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing month archive?
|
||||
* Determines whether the query is for an existing month archive.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4373,7 +4386,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing single page?
|
||||
* Determines whether the query is for an existing single page.
|
||||
*
|
||||
* If the $page parameter is specified, this function will additionally
|
||||
* check if the query is for one of the pages specified.
|
||||
@@ -4426,7 +4439,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a paged result and not for the first page?
|
||||
* Determines whether the query is for a paged result and not for the first page.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4437,7 +4450,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a post or page preview?
|
||||
* Determines whether the query is for a post or page preview.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4448,7 +4461,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for the robots.txt file?
|
||||
* Determines whether the query is for the robots.txt file.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4459,7 +4472,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for the favicon.ico file?
|
||||
* Determines whether the query is for the favicon.ico file.
|
||||
*
|
||||
* @since 5.4.0
|
||||
*
|
||||
@@ -4470,7 +4483,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a search?
|
||||
* Determines whether the query is for a search.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4481,7 +4494,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing single post?
|
||||
* Determines whether the query is for an existing single post.
|
||||
*
|
||||
* Works for any post type excluding pages.
|
||||
*
|
||||
@@ -4535,8 +4548,8 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing single post of any post type (post, attachment, page,
|
||||
* custom post types)?
|
||||
* Determines whether the query is for an existing single post of any post type
|
||||
* (post, attachment, page, custom post types).
|
||||
*
|
||||
* If the $post_types parameter is specified, this function will additionally
|
||||
* check if the query is for one of the Posts Types specified.
|
||||
@@ -4565,7 +4578,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a specific time?
|
||||
* Determines whether the query is for a specific time.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4576,7 +4589,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for a trackback endpoint call?
|
||||
* Determines whether the query is for a trackback endpoint call.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4587,7 +4600,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an existing year archive?
|
||||
* Determines whether the query is for an existing year archive.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4598,7 +4611,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query a 404 (returns no results)?
|
||||
* Determines whether the query is a 404 (returns no results).
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
@@ -4609,7 +4622,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query for an embedded post?
|
||||
* Determines whether the query is for an embedded post.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
@@ -4620,7 +4633,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the query the main query?
|
||||
* Determines whether the query is the main query.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
@@ -4634,7 +4647,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up global post data.
|
||||
* Sets up global post data.
|
||||
*
|
||||
* @since 4.1.0
|
||||
* @since 4.4.0 Added the ability to pass a post ID to `$post`.
|
||||
@@ -4693,7 +4706,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate post data.
|
||||
* Generates post data.
|
||||
*
|
||||
* @since 5.2.0
|
||||
*
|
||||
@@ -4714,11 +4727,22 @@ class WP_Query {
|
||||
|
||||
$authordata = get_userdata( $post->post_author );
|
||||
|
||||
$currentday = mysql2date( 'd.m.y', $post->post_date, false );
|
||||
$currentmonth = mysql2date( 'm', $post->post_date, false );
|
||||
$numpages = 1;
|
||||
$multipage = 0;
|
||||
$page = $this->get( 'page' );
|
||||
$currentday = false;
|
||||
$currentmonth = false;
|
||||
|
||||
$post_date = $post->post_date;
|
||||
if ( ! empty( $post_date ) && '0000-00-00 00:00:00' !== $post_date ) {
|
||||
// Avoid using mysql2date for performance reasons.
|
||||
$currentmonth = substr( $post_date, 5, 2 );
|
||||
$day = substr( $post_date, 8, 2 );
|
||||
$year = substr( $post_date, 2, 2 );
|
||||
|
||||
$currentday = sprintf( '%s.%s.%s', $day, $currentmonth, $year );
|
||||
}
|
||||
|
||||
$numpages = 1;
|
||||
$multipage = 0;
|
||||
$page = $this->get( 'page' );
|
||||
if ( ! $page ) {
|
||||
$page = 1;
|
||||
}
|
||||
@@ -4736,7 +4760,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$content = $post->post_content;
|
||||
if ( false !== strpos( $content, '<!--nextpage-->' ) ) {
|
||||
if ( str_contains( $content, '<!--nextpage-->' ) ) {
|
||||
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
|
||||
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
|
||||
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
|
||||
@@ -4746,7 +4770,7 @@ class WP_Query {
|
||||
$content = str_replace( '<!-- /wp:nextpage -->', '', $content );
|
||||
|
||||
// Ignore nextpage at the beginning of the content.
|
||||
if ( 0 === strpos( $content, '<!--nextpage-->' ) ) {
|
||||
if ( str_starts_with( $content, '<!--nextpage-->' ) ) {
|
||||
$content = substr( $content, 15 );
|
||||
}
|
||||
|
||||
@@ -4785,7 +4809,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cache key.
|
||||
* Generates cache key.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
@@ -4793,7 +4817,6 @@ class WP_Query {
|
||||
*
|
||||
* @param array $args Query arguments.
|
||||
* @param string $sql SQL statement.
|
||||
*
|
||||
* @return string Cache key.
|
||||
*/
|
||||
protected function generate_cache_key( array $args, $sql ) {
|
||||
@@ -4820,7 +4843,7 @@ class WP_Query {
|
||||
* $value is passed by reference to allow it to be modified.
|
||||
* array_walk_recursive() does not return an array.
|
||||
*/
|
||||
function ( &$value ) use ( $wpdb, $placeholder ) {
|
||||
static function ( &$value ) use ( $wpdb, $placeholder ) {
|
||||
if ( is_string( $value ) && str_contains( $value, $placeholder ) ) {
|
||||
$value = $wpdb->remove_placeholder_escape( $value );
|
||||
}
|
||||
@@ -4855,7 +4878,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazyload term meta for posts in the loop.
|
||||
* Lazyloads term meta for posts in the loop.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @deprecated 4.5.0 See wp_queue_posts_for_term_meta_lazyload().
|
||||
@@ -4870,10 +4893,10 @@ class WP_Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazyload comment meta for comments in the loop.
|
||||
* Lazyloads comment meta for comments in the loop.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @deprecated 4.5.0 See wp_queue_comments_for_comment_meta_lazyload().
|
||||
* @deprecated 4.5.0 See wp_lazyload_comment_meta().
|
||||
*
|
||||
* @param mixed $check
|
||||
* @param int $comment_id
|
||||
|
||||
Reference in New Issue
Block a user