Make WordPress Core

Opened 11 years ago

Last modified 3 weeks ago

#35805 reviewing defect (bug)

Reverse page order in wp_list_comments() with newest comments first

Reported by: Ninos Ego Owned by: boonebgorges
Priority: normal Milestone:
Component: Comments Version: 4.4.2
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: template

Description

Hey there,
since wp 4.4 there were lots of bugs in the wp_list_comments()-function. Some of them are already fixed, now I found another one.
If you change the comments order from default (oldest first) to newest first, the page order is wrong (reverse page order).

Example

You have 4 pages by sending following param you get these pages:

page=1 -> 4
page=2 -> 3
page=3 -> 2
page=4 -> 1

How I call this function

Inside the post-loop I'm calling:

<?php
while ( have_posts() ) : the_post();
    get_template_part( 'templates/content', 'comment' );

The template file templates/content-comment.php has following content:

<?php if ( ! defined( 'ABSPATH' ) ) {
        exit;
} ?>

<?php global $withcomments; ?>
<?php $withcomments = 1; ?>
<?php add_filter( 'comments_template', '__return_true' ); ?>

<?php if ( comments_open() || get_comments_number() ) : ?>
        <div class="entry-comment">
                <?php comments_template( '/comments-content.php' ); ?>
        </div>
<?php endif; ?>

And comments-content.php has following part:

<?php
wp_list_comments( array(
        'page'     => $cpaged, // Variable defined before, default: 1
        'per_page' => 2
) );
?>

PS: In ticketing system the version 4.4.2 is not available :-)

Change History (9)

#1 @Ninos Ego
11 years ago

  • Severity normalcritical

#2 @boonebgorges
11 years ago

  • Milestone Awaiting Review4.4.3
  • Owner set to boonebgorges
  • Severity criticalnormal
  • Status newreviewing
  • Version trunk4.4

Thanks for the ticket. I'll review.

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


11 years ago

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


11 years ago

#5 follow-up: @chriscct7
11 years ago

  • Keywords has-patch dev-feedback added

@boonebgorges have you reviewed the patch, or should we punt this a release per discussion in ticket triage?

#6 in reply to: ↑ 5 @boonebgorges
11 years ago

  • Keywords needs-patch needs-unit-tests added; has-patch dev-feedback removed
  • Milestone 4.4.3Future Release
  • Version 4.44.4.2

Replying to chriscct7:

@boonebgorges have you reviewed the patch, or should we punt this a release per discussion in ticket triage?

There's no patch to review. We'll have to punt.

#7 follow-up: @Ninos Ego
10 years ago

Will this bug be fixed in new version 4.5? :)

#8 in reply to: ↑ 7 @boonebgorges
10 years ago

Replying to Ninos Ego:

Will this bug be fixed in new version 4.5? :)

No, unfortunately. I haven't yet been able to find a suitable solution. If you have ideas, please feel free to post them here. Otherwise we'll try for 4.6.

This ticket was mentioned in PR #13269 on WordPress/wordpress-develop by skikken.


3 weeks ago
#9

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

Removed the $start/$end swap after array_reverse() in both paths of Walker::paged_walk() (flat and threaded). Previously page 1 selected the last window of the reversed array (oldest comments displayed newest-first), which is why pages ran backwards. Now pagination follows display order directly: page 1 of a newest-first list starts with the newest comments.

Trac ticket: https://core.trac.wordpress.org/ticket/35805

## Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet

Note: See TracTickets for help on using tickets.