Merged in feature/81-dev-dev01 (pull request #5)
auto-patch 81-dev-dev01-2023-12-05T22_45_26 * auto-patch 81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
@@ -2020,8 +2020,7 @@ class WP_Query {
|
||||
}
|
||||
|
||||
if ( isset( $q['page'] ) ) {
|
||||
$q['page'] = trim( $q['page'], '/' );
|
||||
$q['page'] = absint( $q['page'] );
|
||||
$q['page'] = is_scalar( $q['page'] ) ? absint( trim( $q['page'], '/' ) ) : 0;
|
||||
}
|
||||
|
||||
// If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present.
|
||||
@@ -3179,36 +3178,41 @@ class WP_Query {
|
||||
$cached_results = wp_cache_get( $cache_key, 'post-queries', false, $cache_found );
|
||||
|
||||
if ( $cached_results ) {
|
||||
if ( 'ids' === $q['fields'] ) {
|
||||
/** @var int[] */
|
||||
$this->posts = array_map( 'intval', $cached_results['posts'] );
|
||||
} else {
|
||||
_prime_post_caches( $cached_results['posts'], $q['update_post_term_cache'], $q['update_post_meta_cache'] );
|
||||
/** @var WP_Post[] */
|
||||
$this->posts = array_map( 'get_post', $cached_results['posts'] );
|
||||
}
|
||||
/** @var int[] */
|
||||
$post_ids = array_map( 'intval', $cached_results['posts'] );
|
||||
|
||||
$this->post_count = count( $this->posts );
|
||||
$this->post_count = count( $post_ids );
|
||||
$this->found_posts = $cached_results['found_posts'];
|
||||
$this->max_num_pages = $cached_results['max_num_pages'];
|
||||
|
||||
if ( 'ids' === $q['fields'] ) {
|
||||
$this->posts = $post_ids;
|
||||
|
||||
return $this->posts;
|
||||
} elseif ( 'id=>parent' === $q['fields'] ) {
|
||||
_prime_post_parent_id_caches( $post_ids );
|
||||
|
||||
$post_parent_cache_keys = array();
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$post_parent_cache_keys[] = 'post_parent:' . (string) $post_id;
|
||||
}
|
||||
|
||||
/** @var int[] */
|
||||
$post_parents = array();
|
||||
$post_parents = wp_cache_get_multiple( $post_parent_cache_keys, 'posts' );
|
||||
|
||||
foreach ( $this->posts as $key => $post ) {
|
||||
foreach ( $post_parents as $cache_key => $post_parent ) {
|
||||
$obj = new stdClass();
|
||||
$obj->ID = (int) $post->ID;
|
||||
$obj->post_parent = (int) $post->post_parent;
|
||||
$obj->ID = (int) str_replace( 'post_parent:', '', $cache_key );
|
||||
$obj->post_parent = (int) $post_parent;
|
||||
|
||||
$this->posts[ $key ] = $obj;
|
||||
|
||||
$post_parents[ $obj->ID ] = $obj->post_parent;
|
||||
$this->posts[] = $obj;
|
||||
}
|
||||
|
||||
return $post_parents;
|
||||
} else {
|
||||
_prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
|
||||
/** @var WP_Post[] */
|
||||
$this->posts = array_map( 'get_post', $post_ids );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3246,8 +3250,9 @@ class WP_Query {
|
||||
$this->set_found_posts( $q, $limits );
|
||||
|
||||
/** @var int[] */
|
||||
$post_parents = array();
|
||||
$post_ids = array();
|
||||
$post_parents = array();
|
||||
$post_ids = array();
|
||||
$post_parents_cache = array();
|
||||
|
||||
foreach ( $this->posts as $key => $post ) {
|
||||
$this->posts[ $key ]->ID = (int) $post->ID;
|
||||
@@ -3255,7 +3260,11 @@ class WP_Query {
|
||||
|
||||
$post_parents[ (int) $post->ID ] = (int) $post->post_parent;
|
||||
$post_ids[] = (int) $post->ID;
|
||||
|
||||
$post_parents_cache[ 'post_parent:' . (string) $post->ID ] = (int) $post->post_parent;
|
||||
}
|
||||
// Prime post parent caches, so that on second run, there is not another database query.
|
||||
wp_cache_add_multiple( $post_parents_cache, 'posts' );
|
||||
|
||||
if ( $q['cache_results'] && $id_query_is_cacheable ) {
|
||||
$cache_value = array(
|
||||
@@ -3270,8 +3279,16 @@ class WP_Query {
|
||||
return $post_parents;
|
||||
}
|
||||
|
||||
$is_unfiltered_query = $old_request == $this->request && "{$wpdb->posts}.*" === $fields;
|
||||
|
||||
if ( null === $this->posts ) {
|
||||
$split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
|
||||
$split_the_query = (
|
||||
$is_unfiltered_query
|
||||
&& (
|
||||
wp_using_ext_object_cache()
|
||||
|| ( ! empty( $limits ) && $q['posts_per_page'] < 500 )
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters whether to split the query.
|
||||
@@ -3330,6 +3347,8 @@ class WP_Query {
|
||||
$this->posts = array_map( 'get_post', $this->posts );
|
||||
}
|
||||
|
||||
$unfiltered_posts = $this->posts;
|
||||
|
||||
if ( $q['cache_results'] && $id_query_is_cacheable && ! $cache_found ) {
|
||||
$post_ids = wp_list_pluck( $this->posts, 'ID' );
|
||||
|
||||
@@ -3463,7 +3482,7 @@ class WP_Query {
|
||||
// Move to front, after other stickies.
|
||||
array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
|
||||
// Increment the sticky offset. The next sticky will be placed at this offset.
|
||||
$sticky_offset++;
|
||||
++$sticky_offset;
|
||||
// Remove post from sticky posts array.
|
||||
$offset = array_search( $sticky_post->ID, $sticky_posts, true );
|
||||
unset( $sticky_posts[ $offset ] );
|
||||
@@ -3493,7 +3512,7 @@ class WP_Query {
|
||||
|
||||
foreach ( $stickies as $sticky_post ) {
|
||||
array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
|
||||
$sticky_offset++;
|
||||
++$sticky_offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3522,7 +3541,12 @@ class WP_Query {
|
||||
$this->posts = array_map( 'get_post', $this->posts );
|
||||
|
||||
if ( $q['cache_results'] ) {
|
||||
update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
|
||||
if ( $is_unfiltered_query && $unfiltered_posts === $this->posts ) {
|
||||
update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
|
||||
} else {
|
||||
$post_ids = wp_list_pluck( $this->posts, 'ID' );
|
||||
_prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
|
||||
}
|
||||
}
|
||||
|
||||
/** @var WP_Post */
|
||||
@@ -3613,7 +3637,7 @@ class WP_Query {
|
||||
*/
|
||||
public function next_post() {
|
||||
|
||||
$this->current_post++;
|
||||
++$this->current_post;
|
||||
|
||||
/** @var WP_Post */
|
||||
$this->post = $this->posts[ $this->current_post ];
|
||||
@@ -3723,7 +3747,7 @@ class WP_Query {
|
||||
* @return WP_Comment Comment object.
|
||||
*/
|
||||
public function next_comment() {
|
||||
$this->current_comment++;
|
||||
++$this->current_comment;
|
||||
|
||||
/** @var WP_Comment */
|
||||
$this->comment = $this->comments[ $this->current_comment ];
|
||||
@@ -4312,7 +4336,7 @@ class WP_Query {
|
||||
* If you set a static page for the front page of your site, this function will return
|
||||
* true when viewing that page.
|
||||
*
|
||||
* Otherwise the same as @see WP_Query::is_home()
|
||||
* Otherwise the same as {@see WP_Query::is_home()}.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user