Changeset 53929 for trunk/src/wp-includes/blocks/post-template.php
- Timestamp:
- 08/23/2022 03:40:25 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/post-template.php
r53644 r53929 45 45 $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ]; 46 46 47 $query_args = build_query_vars_from_query_block( $block, $page ); 48 // Override the custom query with the global query if needed. 47 // Use global query if needed. 49 48 $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ); 50 49 if ( $use_global_query ) { 51 50 global $wp_query; 52 if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) { 53 // Unset `offset` because if is set, $wp_query overrides/ignores the paged parameter and breaks pagination. 54 unset( $query_args['offset'] ); 55 $query_args = wp_parse_args( $wp_query->query_vars, $query_args ); 56 57 if ( empty( $query_args['post_type'] ) && is_singular() ) { 58 $query_args['post_type'] = get_post_type( get_the_ID() ); 59 } 60 } 51 $query = clone $wp_query; 52 } else { 53 $query_args = build_query_vars_from_query_block( $block, $page ); 54 $query = new WP_Query( $query_args ); 61 55 } 62 63 $query = new WP_Query( $query_args );64 56 65 57 if ( ! $query->have_posts() ) { … … 108 100 } 109 101 102 /* 103 * Use this function to restore the context of the template tags 104 * from a secondary query loop back to the main query loop. 105 * Since we use two custom loops, it's safest to always restore. 106 */ 110 107 wp_reset_postdata(); 111 108
Note: See TracChangeset
for help on using the changeset viewer.