Skip to content

Commit

Permalink
Handle default category query correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Dec 9, 2024
1 parent 20e46d0 commit 73b6712
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,12 @@ public function parse_tax_query( &$q ) {
continue;
}

if ( 'category' === $taxonomy && empty( $q[ $t->query_var ] ) ) {
// Unlike custom taxonomies, the category field is automatically added to every query.
// Thus, we need to skip it if it is empty.
continue;
}

$tax_query_defaults = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
Expand Down Expand Up @@ -1206,16 +1212,12 @@ public function parse_tax_query( &$q ) {
)
);
} else {
// FIXME: Figure out why 'category' is automatically
// added as a query arg and what to do about it.
if ( 'category' !== $taxonomy ) {
$tax_query[] = array_merge(
$tax_query_defaults,
array(
'operator' => 'EXISTS',
)
);
}
$tax_query[] = array_merge(
$tax_query_defaults,
array(
'operator' => 'EXISTS',
)
);
}
}

Expand Down

0 comments on commit 73b6712

Please sign in to comment.