Skip to content

Commit 06379a3

Browse files
Mamadukat-hamano
andauthored
Query Block: Fix 'parents' argument validation (WordPress#68983)
Co-authored-by: Mamaduka <[email protected]> Co-authored-by: t-hamano <[email protected]>
1 parent edbd360 commit 06379a3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

backport-changelog/6.8/8245.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/WordPress/wordpress-develop/pull/8245
2+
3+
* https://github.com/WordPress/gutenberg/pull/68983

lib/compat/wordpress-6.8/blocks.php

+17
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,20 @@ function gutenberg_update_ignored_hooked_blocks_postmeta( $post ) {
217217
add_filter( 'rest_pre_insert_page', 'gutenberg_update_ignored_hooked_blocks_postmeta' );
218218
add_filter( 'rest_pre_insert_post', 'gutenberg_update_ignored_hooked_blocks_postmeta' );
219219
add_filter( 'rest_pre_insert_wp_block', 'gutenberg_update_ignored_hooked_blocks_postmeta' );
220+
221+
/**
222+
* Update Query `parents` argument validation for hierarchical post types.
223+
* A zero is a valid parent ID for hierarchical post types. Used to display top-level items.
224+
*
225+
* @param array $query The query vars.
226+
* @param WP_Block $block Block instance.
227+
* @return array The filtered query vars.
228+
*/
229+
function gutenberg_parents_query_vars_from_query_block( $query, $block ) {
230+
if ( ! empty( $block->context['query']['parents'] ) && is_post_type_hierarchical( $query['post_type'] ) ) {
231+
$query['post_parent__in'] = array_unique( array_map( 'intval', $block->context['query']['parents'] ) );
232+
}
233+
234+
return $query;
235+
}
236+
add_filter( 'query_loop_block_query_vars', 'gutenberg_parents_query_vars_from_query_block', 10, 2 );

0 commit comments

Comments
 (0)