Opened 5 years ago
Closed 4 months ago
#49428 closed enhancement (invalid)
Extend get_the_post_pagination() to consider total argument
Reported by: | luludak | Owned by: | luludak |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | |
Component: | Posts, Post Types | Keywords: | needs-patch needs-testing |
Focuses: | template | Cc: |
Description
Right now, the usage of the_posts_pagination() is associated directly with the Global query.
By investigating its code in documentation, I noticed that, it practically retrieves the pagination arguments expected by paginate_links($args)
, but it checks on global query ($GLOBALS['wp_query']
) for the maximum number of pages.
However, one of the arguments of paginate_links($args)
is total
, which, by documentation is:
"The total amount of pages. Default is the value WP_Query's max_num_pages or 1.".
Since this exists as argument, my question is, why don't we check for the total
in get_the_posts_pagination()
? That way, we can allow its usage on custom queries (they can propagate the number of pages in the total
argument), not using the global query at all - as this check can block the use of total
as argument.
This fix can be made by changing this code in link-template.php:
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
}
into:
if ( (! empty( $args['total'] ) && $args['total'] > 1 ) || $GLOBALS['wp_query']->max_num_pages > 1 ) {
Note I did not remove the previous check on global query, to ensure backwards compatibility - paginate_links($args)
uses global query to retrieve default arguments - so this part of code is useful. I also check for emptiness and then checking for the argument check in order to apply partial evaluation.
Please note I am adding this ticket for further discussion - since I am new to the community. If this is considered of value, I will be happy to work on the patch.
Change History (1)
#1
in reply to:
↑ description
@
4 months ago
- Resolution set to invalid
- Status changed from assigned to closed
Replying to luludak:
Hi @luludak,
I went through the codebase and found that you can pass the total as an argument, we don't need to add any checks because of two reasons, if the total ain't present as an argument the default value will be assigned due to this line of code:
And if, the user is passing the value of total as an argument, it would get checked and validated through these lines of code:
Hence, I believe that we can conclude and close this ticket.
Thanks.