From 4b910c1c5a6e504731b7882eb301a65de79caae9 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 22 Jul 2021 13:58:11 +0300 Subject: [PATCH 1/2] [Block Library - Query Pagination Numbers]: Fix first page's link --- .../src/query-pagination-numbers/index.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/block-library/src/query-pagination-numbers/index.php b/packages/block-library/src/query-pagination-numbers/index.php index 9d27e88519b65..9423af68ee4dd 100644 --- a/packages/block-library/src/query-pagination-numbers/index.php +++ b/packages/block-library/src/query-pagination-numbers/index.php @@ -45,6 +45,22 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo 'total' => $total, 'prev_next' => false, ); + if ( 1 !== $page ) { + /** + * `paginate_links` doesn't use the provided `format` when the page is `1`. + * This is great for the main query as it removes the extra query params + * making the URL shorter, but in the case of multiple custom queries is + * problematic. It results in returning an empty link which ends up with + * a link to the current page. + * + * A way to address this is to add a `fake` query arg with no value that + * is the same for all custom queries. This way the link is not empty and + * preserves all the other existent query args. + * + * @see https://developer.wordpress.org/reference/functions/paginate_links/ + */ + $paginate_args['add_args'] = array( 'cst' => '' ); + } // We still need to preserve `paged` query param if exists, as is used // for Queries that inherit from global context. $paged = empty( $_GET['paged'] ) ? null : (int) $_GET['paged']; From 317d365c1073e576036eac225640c90f4d2807e0 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 9 Aug 2021 13:38:26 +0300 Subject: [PATCH 2/2] add extra comment for when this should be removed --- .../block-library/src/query-pagination-numbers/index.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/block-library/src/query-pagination-numbers/index.php b/packages/block-library/src/query-pagination-numbers/index.php index 9423af68ee4dd..60fe85efa1f8d 100644 --- a/packages/block-library/src/query-pagination-numbers/index.php +++ b/packages/block-library/src/query-pagination-numbers/index.php @@ -58,6 +58,12 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo * preserves all the other existent query args. * * @see https://developer.wordpress.org/reference/functions/paginate_links/ + * + * The proper fix of this should be in core. Track Ticket: + * @see https://core.trac.wordpress.org/ticket/53868 + * + * TODO: After two WP versions (starting from the WP version the core patch landed), + * we should remove this and call `paginate_links` with the proper new arg. */ $paginate_args['add_args'] = array( 'cst' => '' ); }