WordPress.org

Make WordPress Core

Ticket #18536: 18536-ancestors.diff

File 18536-ancestors.diff, 1.0 KB (added by ryan, 10 years ago)
  • wp-includes/post.php

     
    430430function get_post_ancestors($post) {
    431431        $post = get_post($post);
    432432
    433         if ( !empty($post->ancestors) )
     433        if ( ! isset( $post->ancestors ) )
     434                _get_post_ancestors( $post );
     435
     436        if ( ! empty( $post->ancestors ) )
    434437                return $post->ancestors;
    435438
    436439        return array();
     
    46454648        if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
    46464649                return;
    46474650
    4648         $id = $_post->ancestors[] = $_post->post_parent;
     4651        $id = $_post->ancestors[] = (int) $_post->post_parent;
    46494652        while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
    46504653                // Loop detection: If the ancestor has been seen before, break.
    46514654                if ( ( $ancestor == $_post->ID ) || in_array($ancestor,  $_post->ancestors) )
    46524655                        break;
    4653                 $id = $_post->ancestors[] = $ancestor;
     4656                $id = $_post->ancestors[] = (int) $ancestor;
    46544657        }
    46554658}
    46564659