WordPress.org

Make WordPress Core

Ticket #16574: 16574.diff

File 16574.diff, 827 bytes (added by johnjamesjacoby, 7 years ago)

Use get_posts in _get_posts_ancestors()

  • post.php

     
    45824582                return;
    45834583
    45844584        $id = $_post->ancestors[] = $_post->post_parent;
    4585         while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
     4585        while ( $ancestor = get_posts( array( 'post_parent' => $id, 'numberposts' => 1, 'update_post_meta_cache' => false, 'update_post_term_cache' => false ) ) ) {
    45864586                // Loop detection: If the ancestor has been seen before, break.
    4587                 if ( ( $ancestor == $_post->ID ) || in_array($ancestor,  $_post->ancestors) )
     4587                if ( ( $ancestor[0] == $_post->ID ) || in_array($ancestor[0],  $_post->ancestors) )
    45884588                        break;
    4589                 $id = $_post->ancestors[] = $ancestor;
     4589                $id = $_post->ancestors[] = $ancestor[0];
    45904590        }
    45914591}
    45924592