Make WordPress Core

Ticket #5149: search_pages.diff

File search_pages.diff, 1.8 KB (added by ryan, 19 years ago)
  • wp-includes/query.php

     
    749749                $search = '';
    750750                $groupby = '';
    751751
    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                }
    754758                $post_type = $q['post_type'];
    755759                if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
    756760                        $q['posts_per_page'] = get_option('posts_per_page');
     
    883887                        $q['s'] = stripslashes($q['s']);
    884888                        if ($q['sentence']) {
    885889                                $q['search_terms'] = array($q['s']);
    886                         }
    887                         else {
     890                        } else {
    888891                                preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q[s], $matches);
    889892                                $q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
    890893                        }
     
    892895                        $searchand = '';
    893896                        foreach((array)$q['search_terms'] as $term) {
    894897                                $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}')";
    896899                                $searchand = ' AND ';
    897900                        }
    898                         $term = addslashes_gpc($q['s']);
     901                        $term = $wpdb->escape($q['s']);
    899902                        if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] )
    900903                                $search .= " OR (post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')";
    901904
     
    11451148                        $where .= " AND post_type = 'page'";
    11461149                } elseif ($this->is_single) {
    11471150                        $where .= " AND post_type = 'post'";
     1151                } elseif ( 'any' == $post_type ) {
     1152                        $where .= '';
    11481153                } else {
    11491154                        $where .= " AND post_type = '$post_type'";
    11501155                }