Add post ancestors to the cache for the post object. see #6702 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@7694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d814986be2
commit
a60abc0904
|
@ -165,20 +165,18 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
|
|||
else
|
||||
return $null;
|
||||
} elseif ( is_object($post) ) {
|
||||
_get_post_ancestors($post);
|
||||
wp_cache_add($post->ID, $post, 'posts');
|
||||
$_post = &$post;
|
||||
} else {
|
||||
$post = (int) $post;
|
||||
if ( ! $_post = wp_cache_get($post, 'posts') ) {
|
||||
$_post = & $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post));
|
||||
_get_post_ancestors($_post);
|
||||
wp_cache_add($_post->ID, $_post, 'posts');
|
||||
}
|
||||
}
|
||||
|
||||
// Populate the ancestors field.
|
||||
// Not cached since we don't clear cache for ancestors when a post changes.
|
||||
_get_post_ancestors($_post);
|
||||
|
||||
$_post = sanitize_post($_post, $filter);
|
||||
|
||||
if ( $output == OBJECT ) {
|
||||
|
@ -2739,7 +2737,7 @@ function clean_page_cache($id) {
|
|||
|
||||
if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) )
|
||||
foreach( $children as $cid )
|
||||
clean_post_cache( $cid );
|
||||
clean_page_cache( $cid );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2963,22 +2961,22 @@ function _save_post_hook($post_id, $post) {
|
|||
//
|
||||
|
||||
function _get_post_ancestors(&$_post) {
|
||||
global $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
if ( !isset($_post->ancestors) )
|
||||
return;
|
||||
if ( isset($_post->ancestors) )
|
||||
return;
|
||||
|
||||
$_post->ancestors = array();
|
||||
$_post->ancestors = array();
|
||||
|
||||
if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
|
||||
return;
|
||||
if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
|
||||
return;
|
||||
|
||||
$id = $_post->ancestors[] = $_post->post_parent;
|
||||
while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
|
||||
if ( $id == $ancestor )
|
||||
break;
|
||||
$id = $_post->ancestors[] = $ancestor;
|
||||
}
|
||||
$id = $_post->ancestors[] = $_post->post_parent;
|
||||
while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
|
||||
if ( $id == $ancestor )
|
||||
break;
|
||||
$id = $_post->ancestors[] = $ancestor;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue