-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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' => '' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does cst
stand for here, is it just a random useless param?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Should we land this as a stopgap solution then? 🤔 I'll create a core patch as well. |
Created a core patch here: WordPress/wordpress-develop#1540 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should land this since Gutenberg needs to support at least two WP versions but maybe we should clarify that we can remove it once the core patch lands in an inline comment.
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??(🤔 ).