diff --git a/wp-includes/post.php b/wp-includes/post.php index a0f46ad3b..2926eca86 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3982,8 +3982,9 @@ function clean_page_cache($id) { * @uses update_postmeta_cache() * * @param array $posts Array of Post objects + * @param string $post_type The post type of the posts in $posts */ -function update_post_caches(&$posts) { +function update_post_caches(&$posts, $post_type = 'post') { // No point in doing all this work if we didn't match any posts. if ( !$posts ) return; @@ -3991,11 +3992,14 @@ function update_post_caches(&$posts) { update_post_cache($posts); $post_ids = array(); + foreach ( $posts as $post ) + $post_ids[] = $post->ID; - for ($i = 0; $i < count($posts); $i++) - $post_ids[] = $posts[$i]->ID; + if ( empty($post_type) ) + $post_type = 'post'; - update_object_term_cache($post_ids, 'post'); + if ( !is_array($post_type) && 'any' != $post_type ) + update_object_term_cache($post_ids, $post_type); update_postmeta_cache($post_ids); } diff --git a/wp-includes/query.php b/wp-includes/query.php index 69f19b296..e5e06100e 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1626,6 +1626,9 @@ class WP_Query { if ( !isset($q['suppress_filters']) ) $q['suppress_filters'] = false; + if ( !isset($q['cache_results']) ) + $q['cache_results'] = true; + if ( !isset($q['post_type']) ) { if ( $this->is_search ) $q['post_type'] = 'any'; @@ -2504,7 +2507,8 @@ class WP_Query { $this->posts[$i] = sanitize_post($this->posts[$i], 'raw'); } - update_post_caches($this->posts); + if ( $q['cache_results'] ) + update_post_caches($this->posts, $post_type); if ($this->post_count > 0) { $this->post = $this->posts[0];