[wp-trac] [WordPress Trac] #55751: get_the_posts_navigation() is using incorrect functions to output navigation links

WordPress Trac noreply at wordpress.org
Tue Jun 7 15:24:17 UTC 2022


#55751: get_the_posts_navigation() is using incorrect functions to output
navigation links
--------------------------------------+------------------------------
 Reporter:  jongycastillo             |       Owner:  (none)
     Type:  defect (bug)              |      Status:  reopened
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Posts, Post Types         |     Version:  5.9.3
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------
Changes (by jongycastillo):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 Replying to [comment:4 geisthanen]:
 > The current functionality of {{{ get_posts_navigation}}} is correct. I
 think the main confusion comes from effect the default descending order
 has when querying posts.
 >
 > As mentioned in the documentation:
 >
 [https://developer.wordpress.org/reference/functions/get_next_posts_link/]
 >
 > Because post queries are usually sorted in reverse chronological order,
 {{{get_next_posts_link()}}} usually points to older entries (toward the
 end of the set) and
 > {{{get_previous_posts_link()}}} usually points to newer entries (toward
 the beginning of the set).
 >
 > I've created a collection of tests that proves that the current
 functionality is correct and can be seen here:
 https://github.com/WordPress/wordpress-develop/pull/2792

 Thank you for taking the time to review my ticket. The issue is not with
 the function. The function works as expected. The issue is with the
 filters used inside the function: `next_posts_link_attributes` and
 `previous_posts_link_attributes`. It's misleading that
 `next_posts_link_attributes` applies to the link pointing to previous
 posts and `previous_posts_link_attributes` applies to the link pointing to
 next posts.

 Here is my use case scenario in steps to pinpoint the bug I was having at
 the time.

 1. Add pagination links to index.php:

 ```the_posts_navigation( array(
     'prev_text' => 'Prev',
     'next_text' => 'Next',
 ) );```

 2. Add filter for `next_posts_link_attributes` in functions.php:

 ```add_filter( 'next_posts_link_attributes', function () {
     return 'data-pagination="next-posts"';
 } );```

 3. Add filter for `previous_posts_link_attributes` in functions.php:

 ```add_filter( 'previous_posts_link_attributes', function () {
     return 'data-pagination="prev-posts"';
 } );```

 This is the HTML output from the code above, which shows the attributes
 are not applied to the correct link.

 ```<nav class="navigation posts-navigation" aria-label="Posts">
     <h2 class="screen-reader-text">Posts navigation</h2>
     <div class="nav-links">
         <div class="nav-previous"><a
 href="http://website.test/2020/page/3/" data-pagination="next-
 posts">Prev</a></div>
         <div class="nav-next"><a href="http://website.test/2020/" data-
 pagination="prev-posts">Next</a></div>
     </div>
 </nav>```

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55751#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list