Skip to content

Commit

Permalink
Fix the cat.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc committed Oct 4, 2024
1 parent 4d52073 commit 06cc244
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/query/parseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
}

/**
Expand Down

0 comments on commit 06cc244

Please sign in to comment.