Skip to content

Commit 6224fbf

Browse files
mikachanntsekourascr0ybot
authored
Terms Query: Show nested terms toggle when inheriting (#72510)
Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: cr0ybot <cr0ybot@git.wordpress.org>
1 parent 1de4360 commit 6224fbf

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

packages/block-library/src/term-template/index.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ function render_block_core_term_template( $attributes, $content, $block ) {
3838
// Get the current term and taxonomy from the queried object.
3939
$queried_object = get_queried_object();
4040

41-
// For hierarchical taxonomies, show direct children of the current term.
41+
// For hierarchical taxonomies, show children of the current term.
4242
// For non-hierarchical taxonomies, show all terms (don't set parent).
4343
if ( is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
44-
$query_args['parent'] = $queried_object->term_id;
44+
// If showNested is true, use child_of to include nested terms.
45+
// Otherwise, use parent to show only direct children.
46+
if ( ! empty( $query['showNested'] ) ) {
47+
$query_args['child_of'] = $queried_object->term_id;
48+
} else {
49+
$query_args['parent'] = $queried_object->term_id;
50+
}
4551
}
4652
$query_args['taxonomy'] = $queried_object->taxonomy;
4753
} else {

packages/block-library/src/terms-query/edit/inspector-controls/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export default function TermsQueryInspectorControls( {
5555
templateSlug?.startsWith( 'taxonomy-' ) ||
5656
templateSlug?.startsWith( 'category-' ) ||
5757
templateSlug?.startsWith( 'tag-' );
58-
// Only display the showNested control if the taxonomy is hierarchical and not inheriting.
59-
const displayShowNestedControl = isTaxonomyHierarchical && ! inheritQuery;
58+
// Display the showNested control if the taxonomy is hierarchical.
59+
const displayShowNestedControl = isTaxonomyHierarchical;
6060
const hasIncludeFilter = !! include?.length;
6161

6262
// Labels shared between ToolsPanelItem and its child control.

packages/block-library/src/terms-query/edit/inspector-controls/inherit-control.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ export default function InheritControl( { value, onChange, label } ) {
1717
onChange={ ( newValue ) => {
1818
onChange( {
1919
inherit: newValue === 'default',
20-
// When enabling inherit, hierarchical is not supported.
21-
...( newValue === 'default' ? { showNested: false } : {} ),
2220
} );
2321
} }
2422
help={
2523
value
2624
? __(
27-
'Display terms based on the current taxonomy archive. For hierarchical taxonomies, shows direct children of the current term. For non-hierarchical taxonomies, shows all terms.'
25+
'Display terms based on the current taxonomy archive. For hierarchical taxonomies, shows children of the current term. For non-hierarchical taxonomies, shows all terms.'
2826
)
2927
: __( 'Display terms based on specific criteria.' )
3028
}

0 commit comments

Comments
 (0)