WordPress 3.8
[autoinstalls/wordpress.git] / wp-includes / query.php
index a9300329d19db4fc2e9aaefc277ee15aecef07f5..1ec9566c41166c967569a085449487e8a2a83708 100644 (file)
@@ -1712,7 +1712,7 @@ class WP_Query {
                do_action_ref_array('parse_query', array(&$this));
        }
 
-       /*
+       /**
         * Parses various taxonomy related query vars.
         *
         * @access protected
@@ -1767,26 +1767,39 @@ class WP_Query {
                }
 
                // Category stuff
-               if ( !empty($q['cat']) && '0' != $q['cat'] && !$this->is_singular && $this->query_vars_changed ) {
-                       $q['cat'] = ''.urldecode($q['cat']).'';
-                       $q['cat'] = addslashes_gpc($q['cat']);
-                       $cat_array = preg_split('/[,\s]+/', $q['cat']);
-                       $q['cat'] = '';
-                       $req_cats = array();
-                       foreach ( (array) $cat_array as $cat ) {
-                               $cat = intval($cat);
-                               $req_cats[] = $cat;
-                               $in = ($cat > 0);
-                               $cat = abs($cat);
-                               if ( $in ) {
-                                       $q['category__in'][] = $cat;
-                                       $q['category__in'] = array_merge( $q['category__in'], get_term_children($cat, 'category') );
-                               } else {
-                                       $q['category__not_in'][] = $cat;
-                                       $q['category__not_in'] = array_merge( $q['category__not_in'], get_term_children($cat, 'category') );
-                               }
+               if ( ! empty( $q['cat'] ) && ! $this->is_singular ) {
+                       $cat_in = $cat_not_in = array();
+
+                       $cat_array = preg_split( '/[,\s]+/', urldecode( $q['cat'] ) );
+                       $cat_array = array_map( 'intval', $cat_array );
+                       $q['cat'] = implode( ',', $cat_array );
+
+                       foreach ( $cat_array as $cat ) {
+                               if ( $cat > 0 )
+                                       $cat_in[] = $cat;
+                               elseif ( $cat < 0 )
+                                       $cat_not_in[] = abs( $cat );
+                       }
+
+                       if ( ! empty( $cat_in ) ) {
+                               $tax_query[] = array(
+                                       'taxonomy' => 'category',
+                                       'terms' => $cat_in,
+                                       'field' => 'term_id',
+                                       'include_children' => true
+                               );
                        }
-                       $q['cat'] = implode(',', $req_cats);
+
+                       if ( ! empty( $cat_not_in ) ) {
+                               $tax_query[] = array(
+                                       'taxonomy' => 'category',
+                                       'terms' => $cat_not_in,
+                                       'field' => 'term_id',
+                                       'operator' => 'NOT IN',
+                                       'include_children' => true
+                               );
+                       }
+                       unset( $cat_array, $cat_in, $cat_not_in );
                }
 
                if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) {
@@ -1911,8 +1924,9 @@ class WP_Query {
         *
         * @since 3.7.0
         *
-        * @global type $wpdb
+        * @global wpdb $wpdb
         * @param array $q Query variables.
+        * @return string WHERE clause.
         */
        protected function parse_search( &$q ) {
                global $wpdb;
@@ -1986,8 +2000,8 @@ class WP_Query {
                        else
                                $term = trim( $term, "\"' " );
 
-                       // \p{L} matches a single letter that is not a Chinese, Japanese, etc. char
-                       if ( ! $term || preg_match( '/^\p{L}$/u', $term ) )
+                       // Avoid single A-Z.
+                       if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z]$/i', $term ) ) )
                                continue;
 
                        if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) )
@@ -2017,6 +2031,7 @@ class WP_Query {
                $words = explode( ',', _x( 'about,an,are,as,at,be,by,com,for,from,how,in,is,it,of,on,or,that,the,this,to,was,what,when,where,who,will,with,www',
                        'Comma-separated list of search stopwords in your language' ) );
 
+               $stopwords = array();
                foreach( $words as $word ) {
                        $word = trim( $word, "\r\n\t " );
                        if ( $word )
@@ -3248,20 +3263,25 @@ class WP_Query {
                $this->queried_object_id = 0;
 
                if ( $this->is_category || $this->is_tag || $this->is_tax ) {
-                       $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
-
-                       $query = reset( $tax_query_in_and );
+                       if ( $this->is_category ) {
+                               $term = get_term( $this->get( 'cat' ), 'category' );
+                       } elseif ( $this->is_tag ) {
+                               $term = get_term( $this->get( 'tag_id' ), 'post_tag' );
+                       } else {
+                               $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
+                               $query = reset( $tax_query_in_and );
 
-                       if ( 'term_id' == $query['field'] )
-                               $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
-                       elseif ( $query['terms'] )
-                               $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
+                               if ( 'term_id' == $query['field'] )
+                                       $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
+                               else
+                                       $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
+                       }
 
                        if ( ! empty( $term ) && ! is_wp_error( $term ) )  {
                                $this->queried_object = $term;
                                $this->queried_object_id = (int) $term->term_id;
 
-                               if ( $this->is_category )
+                               if ( $this->is_category && 'category' === $this->queried_object->taxonomy )
                                        _make_cat_compat( $this->queried_object );
                        }
                } elseif ( $this->is_post_type_archive ) {