Ticket #15033: 15033.diff

File 15033.diff, 1.4 KB (added by scribu, 3 years ago)
Line 
1Index: wp-admin/admin-ajax.php
2===================================================================
3--- wp-admin/admin-ajax.php     (revision 15724)
4+++ wp-admin/admin-ajax.php     (working copy)
5@@ -1244,22 +1244,16 @@
6        else
7                $what = 'post';
8 
9-       $s = stripslashes($_POST['ps']);
10-       preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
11-       $search_terms = array_map('_search_terms_tidy', $matches[0]);
12+       $args = array(
13+               'post_type' => $what,
14+               'post_status' => array('draft', 'publish'),
15+               's' => $_POST['ps'],
16+               'showposts' => 50,
17+               'cache_results' => false,
18+       );
19 
20-       $searchand = $search = '';
21-       foreach ( (array) $search_terms as $term ) {
22-               $term = addslashes_gpc($term);
23-               $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
24-               $searchand = ' AND ';
25-       }
26-       $term = $wpdb->escape($s);
27-       if ( count($search_terms) > 1 && $search_terms[0] != $s )
28-               $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
29+       $posts = get_posts( $args );
30 
31-       $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" );
32-
33        if ( ! $posts ) {
34                $posttype = get_post_type_object($what);
35                exit($posttype->labels->not_found);