Skip to content

Commit 066437c

Browse files
committed
unser all query block defaults which are not editable when inherit is true
1 parent 9f565df commit 066437c

File tree

1 file changed

+19
-5
lines changed
  • packages/block-library/src/post-template

1 file changed

+19
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,31 @@ function render_block_core_post_template( $attributes, $content, $block ) {
5151
if ( $use_global_query ) {
5252
global $wp_query;
5353
if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) {
54-
// Unset `offset` because if is set, $wp_query overrides/ignores the paged parameter and breaks pagination.
55-
unset( $query_args['offset'] );
54+
// Unset all the query block query args that cannot be set by the user
55+
// when inherit is set to on.
56+
$block_provided_query_args = array_keys( $query_args );
57+
$user_visible_query_args = [
58+
'ignore_sticky_posts', // Ignore sticky posts
59+
'post__in', // Only sticky posts
60+
'post__not_in' // Exclude sticky posts
61+
];
62+
foreach( $block_provided_query_args as $i => $query_args_key ) {
63+
if( ! in_array( $query_args_key, $user_visible_query_args ) ) {
64+
unset( $query_args[ $query_args_key ] );
65+
}
66+
}
67+
5668

5769
// merge the user settings into the defaults of the query
5870
$query_args = wp_parse_args( $query_args, $wp_query->query_vars );
59-
60-
// Unset the `s` query arg because it is automagically filled by `WP_Query::fill_query_vars` and makes the query believe it is a search query when it is not
71+
72+
// Unset the `s` query arg because it is automagically filled by
73+
// `WP_Query::fill_query_vars` and makes the query believe
74+
// it is a search query when it is not
6175
if ( ! is_search() ) {
6276
unset( $query_args['s'] );
6377
}
64-
78+
6579
if ( empty( $query_args['post_type'] ) && is_singular() ) {
6680
$query_args['post_type'] = get_post_type( get_the_ID() );
6781
}

0 commit comments

Comments
 (0)