X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/53a5df18dd17a11c18781e78349feb3e139096b4..a349837896628462bf8c9bdc27d1477a10fe03eb:/wp-includes/query.php diff --git a/wp-includes/query.php b/wp-includes/query.php index 93d57c2d..446cebca 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -115,7 +115,10 @@ function wp_reset_query() { */ function wp_reset_postdata() { global $wp_query; - $wp_query->reset_postdata(); + + if ( isset( $wp_query ) ) { + $wp_query->reset_postdata(); + } } /* @@ -1712,7 +1715,7 @@ class WP_Query { do_action_ref_array('parse_query', array(&$this)); } - /* + /** * Parses various taxonomy related query vars. * * @access protected @@ -1767,26 +1770,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 + ); + } + + if ( ! empty( $cat_not_in ) ) { + $tax_query[] = array( + 'taxonomy' => 'category', + 'terms' => $cat_not_in, + 'field' => 'term_id', + 'operator' => 'NOT IN', + 'include_children' => true + ); } - $q['cat'] = implode(',', $req_cats); + unset( $cat_array, $cat_in, $cat_not_in ); } if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) { @@ -1911,8 +1927,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; @@ -2017,6 +2034,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 +3266,36 @@ 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 ) { + if ( $this->get( 'cat' ) ) { + $term = get_term( $this->get( 'cat' ), 'category' ); + } elseif ( $this->get( 'category_name' ) ) { + $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' ); + } + } elseif ( $this->is_tag ) { + if ( $this->get( 'tag_id' ) ) { + $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); + } elseif ( $this->get( 'tag' ) ) { + $term = get_term_by( 'slug', $this->get( 'tag' ), '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 ( $query['terms'] ) { + 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 ) {