From d73a826715a9e77b7f74aef2dc77010bdababff6 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 5 Nov 2010 15:26:15 +0000 Subject: [PATCH] Eliminate some queries in get_page_by_path() by consulting cache. Props Denis-de-Bernardy, wojtek.szkutnik. fixes #11373 git-svn-id: https://develop.svn.wordpress.org/trunk@16206 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 1c4dcaf115..3951b47cf2 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3117,7 +3117,10 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { $path = '/' . $leaf_path; $curpage = $page; while ( $curpage->post_parent != 0 ) { - $curpage = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = %d and post_type = %s", $curpage->post_parent, $post_type )); + $post_parent = $curpage->post_parent; + $curpage = wp_cache_get( $post_parent, 'posts' ); + if ( false === $curpage ) + $curpage = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = %d and post_type = %s", $post_parent, $post_type ) ); $path = '/' . $curpage->post_name . $path; }