From 9c4da88e51e3b63f243617d739080fc46568661f Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 31 Jan 2025 14:29:44 +0400 Subject: [PATCH 1/2] Query Block: Fix 'parents' argument validation --- lib/compat/wordpress-6.8/blocks.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/compat/wordpress-6.8/blocks.php b/lib/compat/wordpress-6.8/blocks.php index 90be78cd1457f..1d27215762fe4 100644 --- a/lib/compat/wordpress-6.8/blocks.php +++ b/lib/compat/wordpress-6.8/blocks.php @@ -217,3 +217,20 @@ function gutenberg_update_ignored_hooked_blocks_postmeta( $post ) { add_filter( 'rest_pre_insert_page', 'gutenberg_update_ignored_hooked_blocks_postmeta' ); add_filter( 'rest_pre_insert_post', 'gutenberg_update_ignored_hooked_blocks_postmeta' ); add_filter( 'rest_pre_insert_wp_block', 'gutenberg_update_ignored_hooked_blocks_postmeta' ); + +/** + * Update Query `parents` argument validation for hierarchical post types. + * A zero is a valid parent ID for hierarchical post types. Used to display top-level items. + * + * @param array $query The query vars. + * @param WP_Block $block Block instance. + * @return array The filtered query vars. + */ +function gutenberg_parents_query_vars_from_query_block( $query, $block ) { + if ( ! empty( $block->context['query']['parents'] ) && is_post_type_hierarchical( $query['post_type'] ) ) { + $query['post_parent__in'] = array_unique( array_map( 'intval', $block->context['query']['parents'] ) ); + } + + return $query; +} +add_filter( 'query_loop_block_query_vars', 'gutenberg_parents_query_vars_from_query_block', 10, 2 ); From b09fe7de4b5d15aeafc60da67060d48a33835e2d Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 3 Feb 2025 19:02:46 +0400 Subject: [PATCH 2/2] Add backport changelog entry --- backport-changelog/6.8/8245.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/6.8/8245.md diff --git a/backport-changelog/6.8/8245.md b/backport-changelog/6.8/8245.md new file mode 100644 index 0000000000000..ca9bc3588c5ce --- /dev/null +++ b/backport-changelog/6.8/8245.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/8245 + +* https://github.com/WordPress/gutenberg/pull/68983