43 'format' => "?$page_key=%#%", |
43 'format' => "?$page_key=%#%", |
44 'current' => max( 1, $page ), |
44 'current' => max( 1, $page ), |
45 'total' => $total, |
45 'total' => $total, |
46 'prev_next' => false, |
46 'prev_next' => false, |
47 ); |
47 ); |
|
48 if ( 1 !== $page ) { |
|
49 /** |
|
50 * `paginate_links` doesn't use the provided `format` when the page is `1`. |
|
51 * This is great for the main query as it removes the extra query params |
|
52 * making the URL shorter, but in the case of multiple custom queries is |
|
53 * problematic. It results in returning an empty link which ends up with |
|
54 * a link to the current page. |
|
55 * |
|
56 * A way to address this is to add a `fake` query arg with no value that |
|
57 * is the same for all custom queries. This way the link is not empty and |
|
58 * preserves all the other existent query args. |
|
59 * |
|
60 * @see https://developer.wordpress.org/reference/functions/paginate_links/ |
|
61 * |
|
62 * The proper fix of this should be in core. Track Ticket: |
|
63 * @see https://core.trac.wordpress.org/ticket/53868 |
|
64 * |
|
65 * TODO: After two WP versions (starting from the WP version the core patch landed), |
|
66 * we should remove this and call `paginate_links` with the proper new arg. |
|
67 */ |
|
68 $paginate_args['add_args'] = array( 'cst' => '' ); |
|
69 } |
48 // We still need to preserve `paged` query param if exists, as is used |
70 // We still need to preserve `paged` query param if exists, as is used |
49 // for Queries that inherit from global context. |
71 // for Queries that inherit from global context. |
50 $paged = empty( $_GET['paged'] ) ? null : (int) $_GET['paged']; |
72 $paged = empty( $_GET['paged'] ) ? null : (int) $_GET['paged']; |
51 if ( $paged ) { |
73 if ( $paged ) { |
52 $paginate_args['add_args'] = array( 'paged' => $paged ); |
74 $paginate_args['add_args'] = array( 'paged' => $paged ); |