Skip to content

Comments: Exclude notes from get_page_of_comment().#12552

Open
dhrupo wants to merge 1 commit into
WordPress:trunkfrom
dhrupo:fix-get-page-of-comment-excludes-notes
Open

Comments: Exclude notes from get_page_of_comment().#12552
dhrupo wants to merge 1 commit into
WordPress:trunkfrom
dhrupo:fix-get-page-of-comment-excludes-notes

Conversation

@dhrupo

@dhrupo dhrupo commented Jul 16, 2026

Copy link
Copy Markdown

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

Follow-up to the notes work in #64474.

Summary

Internal note comments (the block-notes feature, 6.9) inflate the page number returned by get_page_of_comment(), which can send visitors to the wrong comments page via get_comment_link().

get_page_of_comment() builds its count query with type => 'all' (its default). WP_Comment_Query deliberately does not exclude the note type when type is 'all' — this was confirmed as intended behavior in #64474:

When using the WP_Comment_Query class, it is correct behaviour that note comment types will be included when type=all is requested. However, on the comment table, the note comment type should always be excluded. — #64474

The public comment list (comments_template()) queries with type => '', 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 later cpage than the one it actually renders on.

Reproduction

  1. Settings → Discussion → enable "Break comments into pages", 1 comment per page.
  2. On a post: add a regular comment, add an internal note dated after it, then add a second regular comment.
  3. 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 passing type__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 changing WP_Comment_Query's intended type=all semantics.

Testing

Added test_notes_should_not_affect_page to Tests_Comment_GetPageOfComment.

  • Before the fix, it fails: Failed asserting that 3 is identical to 2.
  • After the fix, it passes.

Full comment group is green:

./vendor/bin/phpunit --group comment
OK (583 tests, 1428 assertions)

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.

@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dhrupo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

`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.
@dhrupo dhrupo force-pushed the fix-get-page-of-comment-excludes-notes branch from ae3e55f to 880e15c Compare July 16, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant