| 1 | Index: wp-includes/query.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/query.php (revision 18713) |
|---|
| 4 | +++ wp-includes/query.php (working copy) |
|---|
| 5 | @@ -1730,26 +1730,39 @@ |
|---|
| 6 | } |
|---|
| 7 | |
|---|
| 8 | // Category stuff |
|---|
| 9 | - if ( !empty($q['cat']) && '0' != $q['cat'] && !$this->is_singular && $this->query_vars_changed ) { |
|---|
| 10 | - $q['cat'] = ''.urldecode($q['cat']).''; |
|---|
| 11 | - $q['cat'] = addslashes_gpc($q['cat']); |
|---|
| 12 | - $cat_array = preg_split('/[,\s]+/', $q['cat']); |
|---|
| 13 | - $q['cat'] = ''; |
|---|
| 14 | - $req_cats = array(); |
|---|
| 15 | - foreach ( (array) $cat_array as $cat ) { |
|---|
| 16 | - $cat = intval($cat); |
|---|
| 17 | - $req_cats[] = $cat; |
|---|
| 18 | - $in = ($cat > 0); |
|---|
| 19 | - $cat = abs($cat); |
|---|
| 20 | - if ( $in ) { |
|---|
| 21 | - $q['category__in'][] = $cat; |
|---|
| 22 | - $q['category__in'] = array_merge( $q['category__in'], get_term_children($cat, 'category') ); |
|---|
| 23 | - } else { |
|---|
| 24 | - $q['category__not_in'][] = $cat; |
|---|
| 25 | - $q['category__not_in'] = array_merge( $q['category__not_in'], get_term_children($cat, 'category') ); |
|---|
| 26 | - } |
|---|
| 27 | + if ( !empty($q['cat']) && !$this->is_singular ) { |
|---|
| 28 | + $cat_in = $cat_not_in = array(); |
|---|
| 29 | + |
|---|
| 30 | + $cat_array = preg_split('/[,\s]+/', urldecode($q['cat']) ); |
|---|
| 31 | + $cat_array = array_map('intval', $cat_array); |
|---|
| 32 | + $q['cat'] = implode(',', $cat_array); |
|---|
| 33 | + |
|---|
| 34 | + foreach ( $cat_array as $cat ) { |
|---|
| 35 | + if ( $cat > 0 ) |
|---|
| 36 | + $cat_in[] = $cat; |
|---|
| 37 | + elseif ( $cat < 0 ) |
|---|
| 38 | + $cat_not_in[] = abs($cat); |
|---|
| 39 | } |
|---|
| 40 | - $q['cat'] = implode(',', $req_cats); |
|---|
| 41 | + |
|---|
| 42 | + if ( !empty($cat_in) ) { |
|---|
| 43 | + $tax_query[] = array( |
|---|
| 44 | + 'taxonomy' => 'category', |
|---|
| 45 | + 'terms' => $cat_in, |
|---|
| 46 | + 'field' => 'term_id', |
|---|
| 47 | + 'include_children' => true |
|---|
| 48 | + ); |
|---|
| 49 | + } |
|---|
| 50 | + |
|---|
| 51 | + if ( !empty($cat_not_in) ) { |
|---|
| 52 | + $tax_query[] = array( |
|---|
| 53 | + 'taxonomy' => 'category', |
|---|
| 54 | + 'terms' => $cat_not_in, |
|---|
| 55 | + 'field' => 'term_id', |
|---|
| 56 | + 'operator' => 'NOT IN', |
|---|
| 57 | + 'include_children' => true |
|---|
| 58 | + ); |
|---|
| 59 | + } |
|---|
| 60 | + unset($cat_array, $cat_in, $cat_not_in); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | if ( !empty($q['category__in']) ) { |
|---|