From e767570907992459cb78a12f852de7f564633bbf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 9 Dec 2024 17:57:49 +0100 Subject: [PATCH] Add register_taxonomy flag --- src/wp-includes/class-wp-query.php | 6 +++--- src/wp-includes/class-wp-taxonomy.php | 10 ++++++++++ src/wp-includes/taxonomy.php | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 738be677f5e89..0c8a5a3f1537b 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -1173,9 +1173,9 @@ 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. + if ( empty( $q[ $t->query_var ] ) && ! $t->root_taxonomy_archive ) { + // We only allow the term to be empty if the taxonomy is set up to + // show its root archive. continue; } diff --git a/src/wp-includes/class-wp-taxonomy.php b/src/wp-includes/class-wp-taxonomy.php index 7063bea95c18c..758a790b1865d 100644 --- a/src/wp-includes/class-wp-taxonomy.php +++ b/src/wp-includes/class-wp-taxonomy.php @@ -245,6 +245,15 @@ final class WP_Taxonomy { */ public $default_term; + /** + * Whether to show a page for the root taxonomy route, displaying all + * posts that have any term from the taxonomy assigned. + * + * @since 6.8.0 + * @var bool + */ + public $root_taxonomy_archive = false; + /** * Whether terms in this taxonomy should be sorted in the order they are provided to `wp_set_object_terms()`. * @@ -359,6 +368,7 @@ public function set_props( $object_type, $args ) { 'rest_namespace' => false, 'rest_controller_class' => false, 'default_term' => null, + 'root_taxonomy_archive' => false, 'sort' => null, 'args' => null, '_builtin' => false, diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index bebf55ec79bfa..8292ded7c6e54 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -426,6 +426,7 @@ function is_taxonomy_hierarchical( $taxonomy ) { * @since 5.4.0 Added the registered taxonomy object as a return value. * @since 5.5.0 Introduced `default_term` argument. * @since 5.9.0 Introduced `rest_namespace` argument. + * @since 6.8.0 Introduced `root_taxonomy_archive` argument. * * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies. * @@ -506,6 +507,8 @@ function is_taxonomy_hierarchical( $taxonomy ) { * @type string $slug Slug for default term. Default empty. * @type string $description Description for default term. Default empty. * } + * @type bool $root_taxonomy_archive Whether to show a page at the root taxonomy route, displaying all + * posts that have any term from the taxonomy assigned. Default false. * @type bool $sort Whether terms in this taxonomy should be sorted in the order they are * provided to `wp_set_object_terms()`. Default null which equates to false. * @type array $args Array of arguments to automatically use inside `wp_get_object_terms()`