From 73b67127fe7411e50f6b85cdb340f363747d38cf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 9 Dec 2024 16:11:19 +0100 Subject: [PATCH] Handle default category query correctly --- src/wp-includes/class-wp-query.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 4c646dbc2a22a..738be677f5e89 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -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', @@ -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', + ) + ); } }