From 9dc44eb1ece11a75e58f2fdd5fac9aa595cc3783 Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Tue, 10 Dec 2024 11:10:45 +0530 Subject: [PATCH] Query Pagination Previous: Fix total pages calculation based on query inheritance --- .../src/query-pagination-previous/index.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/query-pagination-previous/index.php b/packages/block-library/src/query-pagination-previous/index.php index 328c5c4cf8e9da..eea720d4703e14 100644 --- a/packages/block-library/src/query-pagination-previous/index.php +++ b/packages/block-library/src/query-pagination-previous/index.php @@ -24,13 +24,15 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl global $wp_query; - if ( ! isset( $block->context['query']['inherit'] ) || ! $block->context['query']['inherit'] ) { + if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) { + $total_pages = $wp_query->max_num_pages; + } else { $block_query = new WP_Query( build_query_vars_from_query_block( $block, $page ) ); - $wp_query = $block_query; + $total_pages = $block_query->max_num_pages; + wp_reset_postdata(); } - $total = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page; - wp_reset_postdata(); + $total = ! $max_page || $max_page > $total_pages ? $total_pages : $max_page; $wrapper_attributes = get_block_wrapper_attributes(); $show_label = isset( $block->context['showLabel'] ) ? (bool) $block->context['showLabel'] : true;