Ticket #5149: search_pages.diff
| File search_pages.diff, 1.8 KB (added by ryan, 5 years ago) |
|---|
-
wp-includes/query.php
749 749 $search = ''; 750 750 $groupby = ''; 751 751 752 if ( !isset($q['post_type']) ) 753 $q['post_type'] = 'post'; 752 if ( !isset($q['post_type']) ) { 753 if ( $this->is_search ) 754 $q['post_type'] = 'any'; 755 else 756 $q['post_type'] = 'post'; 757 } 754 758 $post_type = $q['post_type']; 755 759 if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 ) 756 760 $q['posts_per_page'] = get_option('posts_per_page'); … … 883 887 $q['s'] = stripslashes($q['s']); 884 888 if ($q['sentence']) { 885 889 $q['search_terms'] = array($q['s']); 886 } 887 else { 890 } else { 888 891 preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q[s], $matches); 889 892 $q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]); 890 893 } … … 892 895 $searchand = ''; 893 896 foreach((array)$q['search_terms'] as $term) { 894 897 $term = addslashes_gpc($term); 895 $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}') )";898 $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')"; 896 899 $searchand = ' AND '; 897 900 } 898 $term = addslashes_gpc($q['s']);901 $term = $wpdb->escape($q['s']); 899 902 if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] ) 900 903 $search .= " OR (post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')"; 901 904 … … 1145 1148 $where .= " AND post_type = 'page'"; 1146 1149 } elseif ($this->is_single) { 1147 1150 $where .= " AND post_type = 'post'"; 1151 } elseif ( 'any' == $post_type ) { 1152 $where .= ''; 1148 1153 } else { 1149 1154 $where .= " AND post_type = '$post_type'"; 1150 1155 }
