[Block Library - Query Pagination Numbers]: Fix first page's link #33629
Conversation
* | ||
* @see https://developer.wordpress.org/reference/functions/paginate_links/ | ||
*/ | ||
$paginate_args['add_args'] = array( 'cst' => '' ); |
youknowriad
Jul 22, 2021
Contributor
What does cst
stand for here, is it just a random useless param?
What does cst
stand for here, is it just a random useless param?
youknowriad
Jul 22, 2021
•
Contributor
I feel ideally, we should add a dedicated argument/option in paginate_links
to disable the default behavior of skipping format
. That said, this is fine a stopgap solution.
I feel ideally, we should add a dedicated argument/option in paginate_links
to disable the default behavior of skipping format
. That said, this is fine a stopgap solution.
swissspidy
Jul 22, 2021
Member
So this causes ?cst
to be added to every link? 🤔 Seems a bit unexpected/weird.
Why not just filter paginate_links_output
?
Theoretically it could cause some confusion if someone's already using a query arg with this name and expects it to do something else.
Could you perhaps share what the expected output is with this change?
Agreed that this should be fixed with a patch in core.
So this causes ?cst
to be added to every link?
Why not just filter paginate_links_output
?
Theoretically it could cause some confusion if someone's already using a query arg with this name and expects it to do something else.
Could you perhaps share what the expected output is with this change?
Agreed that this should be fixed with a patch in core.
ntsekouras
Jul 22, 2021
Author
Contributor
What does cst stand for here, is it just a random useless param?
Yes.
Theoretically it could cause some confusion if someone's already using a query arg with this name
We can change this to whatever. That's why I didn't used a single character, as it would increase those chances. I'm open to any suggestions.
Why not just filter paginate_links_output?
This would require parsing the html string and I'm not sure it worths it and how complicated it can get with other filters having been applied before, to other parts of this html construction. An extra variable in core should be the best solution probably.
What does cst stand for here, is it just a random useless param?
Yes.
Theoretically it could cause some confusion if someone's already using a query arg with this name
We can change this to whatever. That's why I didn't used a single character, as it would increase those chances. I'm open to any suggestions.
Why not just filter paginate_links_output?
This would require parsing the html string and I'm not sure it worths it and how complicated it can get with other filters having been applied before, to other parts of this html construction. An extra variable in core should be the best solution probably.
Description
Fixes: #32792
paginate_links
doesn't use the providedformat
when the page is1
. 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.Reference: https://developer.wordpress.org/reference/functions/paginate_links/
$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); $link = str_replace( '%#%', $n, $link );
How has this been tested?
Query Loop
blocks withQueryPaginationNumbers
blocks check that by clicking another page number first, the pagination link for the first page (1
), works as expected.Query
in a page as well, but it's better to have multipleQuery Loop
blocks which can be bothcustom
and ones thatinherit the global query
.Notes
link
is not empty - thus thehacky
approach here to add an emptyquery arg
.I couldn't find any better alternative so a more elegant solution would be more than welcomed. We could also look at making some changes in core🤔 ).
paginate_links
but needs more exploration there. For example we could extend thepaginate_links
filter by passing the currentpage number ($n)
and use this filter in the block??(