Skip to content

Commit

Permalink
Add register_taxonomy flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Dec 9, 2024
1 parent 73b6712 commit e767570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions src/wp-includes/class-wp-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
*
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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()`
Expand Down

0 comments on commit e767570

Please sign in to comment.