Update object term cache for custom post types. props scribu, fixes #12989.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14310 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-04-29 20:43:59 +00:00
parent 6252553037
commit 7ef5f08d00
2 changed files with 13 additions and 5 deletions

View File

@ -3982,8 +3982,9 @@ function clean_page_cache($id) {
* @uses update_postmeta_cache() * @uses update_postmeta_cache()
* *
* @param array $posts Array of Post objects * @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. // No point in doing all this work if we didn't match any posts.
if ( !$posts ) if ( !$posts )
return; return;
@ -3991,11 +3992,14 @@ function update_post_caches(&$posts) {
update_post_cache($posts); update_post_cache($posts);
$post_ids = array(); $post_ids = array();
foreach ( $posts as $post )
$post_ids[] = $post->ID;
for ($i = 0; $i < count($posts); $i++) if ( empty($post_type) )
$post_ids[] = $posts[$i]->ID; $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); update_postmeta_cache($post_ids);
} }

View File

@ -1626,6 +1626,9 @@ class WP_Query {
if ( !isset($q['suppress_filters']) ) if ( !isset($q['suppress_filters']) )
$q['suppress_filters'] = false; $q['suppress_filters'] = false;
if ( !isset($q['cache_results']) )
$q['cache_results'] = true;
if ( !isset($q['post_type']) ) { if ( !isset($q['post_type']) ) {
if ( $this->is_search ) if ( $this->is_search )
$q['post_type'] = 'any'; $q['post_type'] = 'any';
@ -2504,7 +2507,8 @@ class WP_Query {
$this->posts[$i] = sanitize_post($this->posts[$i], 'raw'); $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) { if ($this->post_count > 0) {
$this->post = $this->posts[0]; $this->post = $this->posts[0];