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:
parent
4e30ca031b
commit
3b1b03e4c4
|
@ -1762,8 +1762,16 @@ class WP_Query {
|
||||||
$q['cat'] = implode(',', $req_cats);
|
$q['cat'] = implode(',', $req_cats);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($q['category__in']) ) {
|
if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) {
|
||||||
$q['category__in'] = array_map('absint', array_unique( (array) $q['category__in'] ) );
|
$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(
|
$tax_query[] = array(
|
||||||
'taxonomy' => 'category',
|
'taxonomy' => 'category',
|
||||||
'terms' => $q['category__in'],
|
'terms' => $q['category__in'],
|
||||||
|
@ -1772,8 +1780,8 @@ class WP_Query {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($q['category__not_in']) ) {
|
if ( ! empty($q['category__not_in']) ) {
|
||||||
$q['category__not_in'] = array_map('absint', array_unique( (array) $q['category__not_in'] ) );
|
$q['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) );
|
||||||
$tax_query[] = array(
|
$tax_query[] = array(
|
||||||
'taxonomy' => 'category',
|
'taxonomy' => 'category',
|
||||||
'terms' => $q['category__not_in'],
|
'terms' => $q['category__not_in'],
|
||||||
|
@ -1782,8 +1790,8 @@ class WP_Query {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($q['category__and']) ) {
|
if ( ! empty($q['category__and']) ) {
|
||||||
$q['category__and'] = array_map('absint', array_unique( (array) $q['category__and'] ) );
|
$q['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) );
|
||||||
$tax_query[] = array(
|
$tax_query[] = array(
|
||||||
'taxonomy' => 'category',
|
'taxonomy' => 'category',
|
||||||
'terms' => $q['category__and'],
|
'terms' => $q['category__and'],
|
||||||
|
|
Loading…
Reference in New Issue