From 17d32ebc8ff52856dcde5b5d40e3d039052813f7 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 23 Aug 2019 16:05:56 +0000 Subject: [PATCH] Taxonomy: Ensure consistency of `hide_empty` in term queries when `taxonomy` is excluded. When querying for terms in hierarchical categories using `hide_empty=true`, results have historically included parent terms which are themselves unattached to any objects (are "empty") but which have non-empty descendent terms. Because this process involves walking the descendant tree, we avoid it when we detect that the queried taxonomies are not hierarchical. (This behavior was introduced in [5525].) When the `taxonomy` parameter of `get_terms()` was made optional - see #35495, [36614] - it affected the mechanism for avoiding unneccessary tree walks, since there may not be any explicitly declared taxonomies to run through `is_taxonomy_hierarchical()`. As a result, term queries excluding `taxonomy` did not check descendants, and empty parents with non-empty children were not included in `hide_empty` results. We correct the behavior by crawling term descendants when the `taxonomy` argument is absent, which means that we're querying for terms in all taxonomies. Props smerriman. Fixes #37728. Built from https://develop.svn.wordpress.org/trunk@45888 git-svn-id: http://core.svn.wordpress.org/trunk@45699 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-term-query.php | 3 +++ wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-term-query.php b/wp-includes/class-wp-term-query.php index 13c0ea3f80..a7d400daa8 100644 --- a/wp-includes/class-wp-term-query.php +++ b/wp-includes/class-wp-term-query.php @@ -326,6 +326,9 @@ class WP_Term_Query { $has_hierarchical_tax = true; } } + } else { + // When no taxonomies are provided, assume we have to descend the tree. + $has_hierarchical_tax = true; } if ( ! $has_hierarchical_tax ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 51d14b8ec4..58c682acda 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45887'; +$wp_version = '5.3-alpha-45888'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.