WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 8 months ago

#36701 new enhancement

Pages parameter for get_comments

Reported by: mireillesan Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.5.1
Component: Comments Keywords: needs-patch needs-unit-tests close
Focuses: Cc:

Description

Would it also be possible to add a $paged parameter to get_comments?

That way we can have more control over the pagination.

For example: Reviews are usually just comments with an extra meta_key. To display only the reviews, we can easily filter them inside get_comments.

There's one issue, the pagination (paginate_comments_links) grabs total comment count and ignoring the fact that get_comments only displays selected comments based on meta_key.

Hope it makes sense what I wrote, if not, just let me know.

Change History (2)

#1 @boonebgorges
2 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

Hi @mireillesan - Thanks for the ticket, and welcome to WordPress Trac!

Pagination parameters seem like a good idea. The parameter name for the page number, based on what we use in other query classes, would be paged. We are less consistent about the "per page" parameter name - WP_Query calls it posts_per_page, while WP_User_Query calls it number. Since we already have number in WP_Comment_Query, it makes sense to use it here too.

When introducing new parameters like this, which are conceptually similar to other existing params (in this case, offset), we should have unit tests that demonstrate which one takes precedence - ie, what happens when you pass offset=21&paged=5&number=20.

#2 @birgire
8 months ago

  • Keywords close added

Seems to be resolved in #38268

Note: See TracTickets for help on using tickets.