Convert category__and to category__in (less expensive) and unset it when only one category is passed. Adds unit tests.

Fixes #24245.



Built from https://develop.svn.wordpress.org/trunk@25238


git-svn-id: http://core.svn.wordpress.org/trunk@25208 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2013-09-04 18:17:09 +00:00
parent 4e30ca031b
commit 3b1b03e4c4

View File

@ -1762,8 +1762,16 @@ class WP_Query {
$q['cat'] = implode(',', $req_cats);
}
if ( !empty($q['category__in']) ) {
$q['category__in'] = array_map('absint', array_unique( (array) $q['category__in'] ) );
if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) {
$q['category__and'] = (array) $q['category__and'];
if ( ! isset( $q['category__in'] ) )
$q['category__in'] = array();
$q['category__in'][] = absint( reset( $q['category__and'] ) );
unset( $q['category__and'] );
}
if ( ! empty( $q['category__in'] ) ) {
$q['category__in'] = array_map( 'absint', array_unique( (array) $q['category__in'] ) );
$tax_query[] = array(
'taxonomy' => 'category',
'terms' => $q['category__in'],
@ -1772,8 +1780,8 @@ class WP_Query {
);
}
if ( !empty($q['category__not_in']) ) {
$q['category__not_in'] = array_map('absint', array_unique( (array) $q['category__not_in'] ) );
if ( ! empty($q['category__not_in']) ) {
$q['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) );
$tax_query[] = array(
'taxonomy' => 'category',
'terms' => $q['category__not_in'],
@ -1782,8 +1790,8 @@ class WP_Query {
);
}
if ( !empty($q['category__and']) ) {
$q['category__and'] = array_map('absint', array_unique( (array) $q['category__and'] ) );
if ( ! empty($q['category__and']) ) {
$q['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) );
$tax_query[] = array(
'taxonomy' => 'category',
'terms' => $q['category__and'],