diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index be646a3268682..1fb08a4520895 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -1212,12 +1212,9 @@ public function parse_tax_query( &$q ) { } // If query string 'cat' is an array, implode it. - if ( ! is_array( $q['cat'] ) ) { - $q['cat'] = explode( ',', $q['cat'] ); - $q['cat'] = array_map( 'trim', $q['cat'] ); + if ( is_array( $q['cat'] ) ) { + $q['cat'] = implode( ',', $q['cat'] ); } - sort( $q['cat'] ); - $q['cat'] = implode( ',', $q['cat'] ); // Category stuff. @@ -1227,7 +1224,8 @@ public function parse_tax_query( &$q ) { $cat_array = preg_split( '/[,\s]+/', urldecode( $q['cat'] ) ); $cat_array = array_map( 'intval', $cat_array ); - $q['cat'] = implode( ',', $cat_array ); + sort( $cat_array ); + $q['cat'] = implode( ',', $cat_array ); foreach ( $cat_array as $cat ) { if ( $cat > 0 ) { diff --git a/tests/phpunit/tests/query/parseQuery.php b/tests/phpunit/tests/query/parseQuery.php index bbf3f1217fb2e..94ced1ecd6e75 100644 --- a/tests/phpunit/tests/query/parseQuery.php +++ b/tests/phpunit/tests/query/parseQuery.php @@ -151,7 +151,7 @@ public function test_parse_query_cat_array_mixed() { ) ); - $this->assertSame( '1,-1', $q->query_vars['cat'] ); + $this->assertSame( '-1,1', $q->query_vars['cat'] ); } /**