From f5bf3676b1cb1d5898ed320bc78eee2a889e726e Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 27 Jun 2016 11:51:30 +0000 Subject: [PATCH] Nav Menus: Use `WP_Query` for quick searches. `the_post()` sets the `$in_the_loop` property to true which is unexpected in the admin if you're using filters which should only affect real loops. Props ruud@joyo. Fixes #27042. Built from https://develop.svn.wordpress.org/trunk@37881 git-svn-id: http://core.svn.wordpress.org/trunk@37822 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/nav-menu.php | 28 ++++++++++++++++------------ wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index f07b25e36c..b65e28ce98 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -70,24 +70,28 @@ function _wp_ajax_menu_quick_search( $request = array() ) { } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) { if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) { - query_posts(array( - 'posts_per_page' => 10, - 'post_type' => $matches[2], - 's' => $query, - )); - if ( ! have_posts() ) + $search_results_query = new WP_Query( array( + 'no_found_rows' => true, + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false, + 'posts_per_page' => 10, + 'post_type' => $matches[2], + 's' => $query, + ) ); + if ( ! $search_results_query->have_posts() ) { return; - while ( have_posts() ) { - the_post(); + } + while ( $search_results_query->have_posts() ) { + $post = $search_results_query->next_post(); if ( 'markup' == $response_format ) { - $var_by_ref = get_the_ID(); + $var_by_ref = $post->ID; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { echo wp_json_encode( array( - 'ID' => get_the_ID(), - 'post_title' => get_the_title(), - 'post_type' => get_post_type(), + 'ID' => $post->ID, + 'post_title' => get_the_title( $post->ID ), + 'post_type' => $matches[2], ) ); echo "\n"; diff --git a/wp-includes/version.php b/wp-includes/version.php index 293c4033b6..1afe657141 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37880'; +$wp_version = '4.6-alpha-37881'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.