Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#42813 closed feature request (invalid)

the_posts_pagination() should have second parameter

Reported by: khoipro's profile khoipro Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: template Cc:



When working with the_posts_pagination(), I found it does not work well with Custom Page Template which contains post list. It's because a function get_the_posts_pagination uses condition $GLOBALSwp_query?->max_num_pages > 1 before outputing.

As you know, the custom page template cannot make $wp_query to display a list of posts in this case.
A better solution is keeping the second parameter which keeps $GLOBALSwp_query? as a default argument.

A complete optimized function should be:

function get_the_posts_pagination( $args = array(), $the_query = $GLOBALS['wp_query'] ) {
        $navigation = '';

        // Don't print empty markup if there's only one page.
        if ( $the_query->max_num_pages > 1 ) {
                $args = wp_parse_args( $args, array(
                        'mid_size'           => 1,
                        'prev_text'          => _x( 'Previous', 'previous set of posts' ),
                        'next_text'          => _x( 'Next', 'next set of posts' ),
                        'screen_reader_text' => __( 'Posts navigation' ),
                ) );

                // Make sure we get a string back. Plain is the next best thing.
                if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
                        $args['type'] = 'plain';

                // Set up paginated links.
                $links = paginate_links( $args );

                if ( $links ) {
                        $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] );

        return $navigation;

Related Cases

Someone tried to remove default $wp_query and replace with a custom query which I don't feel safe at all:

If we don't use the_posts_pagination(), we must make a custom pagination which is very waste time to re-do something WordPress the_posts_pagination should do:

Thank you,

Change History (2)

#1 @khoipro
6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

#2 @ocean90
6 years ago

  • Milestone Awaiting Review deleted
  • Version 4.9.1 deleted
Note: See TracTickets for help on using tickets.