From 54e1f4abfdc61d02227b951b6d6131611fc27ed9 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 19 Sep 2012 18:11:43 +0000 Subject: [PATCH] Improve performance of query in get_adjacent_post(). Get the ID and then call get_post(). Props apokalyptik, nacin, javert03. fixes #18120 git-svn-id: https://develop.svn.wordpress.org/trunk@21919 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/link-template.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index e73764c5a3..0532e0abe0 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1166,23 +1166,23 @@ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $pr $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories ); $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); - $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; + $query = "SELECT p.id FROM $wpdb->posts AS p $join $where $sort"; $query_key = 'adjacent_post_' . md5($query); $result = wp_cache_get($query_key, 'counts'); if ( false !== $result ) { - if ( is_object( $result ) ) - $result = new WP_Post( $result ); + if ( $result ) + $result = get_post( $result ); return $result; } - $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort"); + $result = $wpdb->get_var( $query ); if ( null === $result ) $result = ''; wp_cache_set($query_key, $result, 'counts'); - if ( is_object( $result ) ) - $result = new WP_Post( $result ); + if ( $result ) + $result = get_post( $result ); return $result; } @@ -2057,7 +2057,7 @@ function plugins_url($path = '', $plugin = '') { else $url = WP_PLUGIN_URL; - + $url = set_url_scheme( $url ); if ( !empty($plugin) && is_string($plugin) ) {