Skip to content

Commit

Permalink
Query Block: Fix 'parents' argument validation (WordPress#68983)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2025
1 parent edbd360 commit 06379a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backport-changelog/6.8/8245.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/8245

* https://github.com/WordPress/gutenberg/pull/68983
17 changes: 17 additions & 0 deletions lib/compat/wordpress-6.8/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

0 comments on commit 06379a3

Please sign in to comment.