WordPress.org

Make WordPress Core

Ticket #15033: 15033-B.diff

File 15033-B.diff, 1.4 KB (added by kevinB, 3 years ago)

Make find_posts query use get_posts() -- without suppressing filters

  • admin-ajax.php

     
    12601260        else 
    12611261                $what = 'post'; 
    12621262 
    1263         $s = stripslashes($_POST['ps']); 
    1264         preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); 
    1265         $search_terms = array_map('_search_terms_tidy', $matches[0]); 
     1263        $args = array(  
     1264                'post_type' => $what,  
     1265                'post_status' => array('draft', 'publish'),  
     1266                's' => $_POST['ps'],  
     1267                'showposts' => 50,  
     1268                'cache_results' => false,  
     1269                'suppress_filters' => false, 
     1270        ); 
    12661271 
    1267         $searchand = $search = ''; 
    1268         foreach ( (array) $search_terms as $term ) { 
    1269                 $term = esc_sql( like_escape( $term ) ); 
    1270                 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))"; 
    1271                 $searchand = ' AND '; 
    1272         } 
    1273         $term = esc_sql( like_escape( $s ) ); 
    1274         if ( count($search_terms) > 1 && $search_terms[0] != $s ) 
    1275                 $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')"; 
     1272        $posts = get_posts( $args );  
    12761273 
    1277         $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" ); 
    1278  
    12791274        if ( ! $posts ) { 
    12801275                $posttype = get_post_type_object($what); 
    12811276                exit($posttype->labels->not_found);