Comments: Exclude notes from get_page_of_comment().#12552
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
`get_page_of_comment()` defaults to the 'all' comment type, which `WP_Comment_Query` does not exclude the internal 'note' comment type from. As a result, a note dated before a given comment inflates the calculated page number, so `get_comment_link()` can produce a `cpage` that points to the wrong comments page. The public comment list excludes notes, so the pagination calculation must exclude them too. Pass `type__not_in => array( 'note' )` to the count query so notes never affect the page a regular comment appears on. This mirrors the approach taken for the comments list table in [61525] / #64474. Adds a regression test. Fixes #65642.
ae3e55f to
880e15c
Compare
Trac ticket: https://core.trac.wordpress.org/ticket/65642
Follow-up to the notes work in #64474.
Summary
Internal
notecomments (the block-notes feature, 6.9) inflate the page number returned byget_page_of_comment(), which can send visitors to the wrong comments page viaget_comment_link().get_page_of_comment()builds its count query withtype => 'all'(its default).WP_Comment_Querydeliberately does not exclude thenotetype whentypeis'all'— this was confirmed as intended behavior in #64474:The public comment list (
comments_template()) queries withtype => '', which does exclude notes. So the two disagree: the displayed list omits notes, but the pagination math counts them. On a post that has a note and "Break comments into pages" enabled, a note dated before a given comment shifts that comment onto a latercpagethan the one it actually renders on.Reproduction
get_page_of_comment()for the second comment returns 3 instead of 2 — the note occupies a phantom page.Fix
Exclude notes from the count query in
get_page_of_comment()by passingtype__not_in => array( 'note' ), aligning the pagination calculation with the public comment display. This mirrors the fix applied to the comments list table in [61525] / #64474 (type__not_in => 'note'at the surface that must never show notes), rather than changingWP_Comment_Query's intendedtype=allsemantics.Testing
Added
test_notes_should_not_affect_pagetoTests_Comment_GetPageOfComment.Failed asserting that 3 is identical to 2.Full comment group is green:
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Investigating the notes-exclusion surfaces, reproducing the pagination bug, implementing the fix, and writing the regression test. All changes were reviewed by me.