Make WordPress Core

Changeset 37881


Ignore:
Timestamp:
06/27/2016 11:50:31 AM (9 years ago)
Author:
ocean90
Message:

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.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/nav-menu.php

    r37748 r37881  
    7171    } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
    7272        if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
    73             query_posts(array(
    74                 'posts_per_page' => 10,
    75                 'post_type' => $matches[2],
    76                 's' => $query,
    77             ));
    78             if ( ! have_posts() )
     73            $search_results_query = new WP_Query( array(
     74                'no_found_rows'          => true,
     75                'update_post_meta_cache' => false,
     76                'update_post_term_cache' => false,
     77                'posts_per_page'         => 10,
     78                'post_type'              => $matches[2],
     79                's'                      => $query,
     80            ) );
     81            if ( ! $search_results_query->have_posts() ) {
    7982                return;
    80             while ( have_posts() ) {
    81                 the_post();
     83            }
     84            while ( $search_results_query->have_posts() ) {
     85                $post = $search_results_query->next_post();
    8286                if ( 'markup' == $response_format ) {
    83                     $var_by_ref = get_the_ID();
     87                    $var_by_ref = $post->ID;
    8488                    echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
    8589                } elseif ( 'json' == $response_format ) {
    8690                    echo wp_json_encode(
    8791                        array(
    88                             'ID' => get_the_ID(),
    89                             'post_title' => get_the_title(),
    90                             'post_type' => get_post_type(),
     92                            'ID' => $post->ID,
     93                            'post_title' => get_the_title( $post->ID ),
     94                            'post_type' => $matches[2],
    9195                        )
    9296                    );
Note: See TracChangeset for help on using the changeset viewer.