Ticket #16574: 16574.diff

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

Use get_posts in _get_posts_ancestors()

Line 
1Index: post.php
2--- post.php Remotely Modified (Based On HEAD)
3+++ post.php Locally Modified (Based On LOCAL)
4@@ -4582,11 +4582,11 @@
5                return;
6 
7        $id = $_post->ancestors[] = $_post->post_parent;
8-       while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
9+       while ( $ancestor = get_posts( array( 'post_parent' => $id, 'numberposts' => 1, 'update_post_meta_cache' => false, 'update_post_term_cache' => false ) ) ) {
10                // Loop detection: If the ancestor has been seen before, break.
11-               if ( ( $ancestor == $_post->ID ) || in_array($ancestor,  $_post->ancestors) )
12+               if ( ( $ancestor[0] == $_post->ID ) || in_array($ancestor[0],  $_post->ancestors) )
13                        break;
14-               $id = $_post->ancestors[] = $ancestor;
15+               $id = $_post->ancestors[] = $ancestor[0];
16        }
17 }
18