From 1a4109215855b6143b0077485d4d44fade4e01d2 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 12 Mar 2012 18:23:48 +0000 Subject: [PATCH] Call _get_post_ancestors() from get_post_ancestors() if the ancestors property is not set in the post object. Works around situations where ancestors is not set in the cached version of the post object. see #18536 git-svn-id: https://develop.svn.wordpress.org/trunk@20171 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 9 ++++++--- wp-includes/query.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index e2ef3888b5..2ca5f3cc62 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -430,7 +430,10 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') { function get_post_ancestors($post) { $post = get_post($post); - if ( !empty($post->ancestors) ) + if ( ! isset( $post->ancestors ) ) + _get_post_ancestors( $post ); + + if ( ! empty( $post->ancestors ) ) return $post->ancestors; return array(); @@ -4645,12 +4648,12 @@ function _get_post_ancestors(&$_post) { if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent ) return; - $id = $_post->ancestors[] = $_post->post_parent; + $id = $_post->ancestors[] = (int) $_post->post_parent; while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) { // Loop detection: If the ancestor has been seen before, break. if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) ) break; - $id = $_post->ancestors[] = $ancestor; + $id = $_post->ancestors[] = (int) $ancestor; } } diff --git a/wp-includes/query.php b/wp-includes/query.php index c621470a53..9a69ac6abc 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2671,7 +2671,7 @@ class WP_Query { // Check post status to determine if post should be displayed. if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { - $status = get_post_status($this->posts[0]); + $status = get_post_status($this->posts[0]->ID); $post_status_obj = get_post_status_object($status); //$type = get_post_type($this->posts[0]); if ( !$post_status_obj->public ) {