Opened 3 years ago
#49428 assigned enhancement
Extend get_the_post_pagination() to consider total argument
Reported by: |
|
Owned by: |
|
---|---|---|---|
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.