[wp-trac] [WordPress Trac] #49428: Extend get_the_post_pagination() to consider total argument
WordPress Trac
noreply at wordpress.org
Thu Feb 13 16:57:34 UTC 2020
#49428: Extend get_the_post_pagination() to consider total argument
-------------------------------+---------------------------------------
Reporter: luludak | Owner: luludak
Type: enhancement | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version:
Severity: minor | Keywords: needs-patch needs-testing
Focuses: template |
-------------------------------+---------------------------------------
Right now, the usage of the_posts_pagination() is associated directly with
the Global query.
By investigating its code in
[https://developer.wordpress.org/reference/functions/the_posts_pagination/
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49428>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list