Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#63130 new enhancement

Add comment_count Support to REST API for Enhanced Sorting and Gutenberg Integration

Reported by: vipulpatil's profile vipulpatil Owned by:
Milestone: Awaiting Review Priority: normal
Severity: blocker Version: trunk
Component: REST API Keywords: has-patch
Focuses: rest-api Cc:

Description

Currently, the REST API does not support sorting posts by comment_count, which limits the ability to retrieve posts ordered by the number of comments. Adding comment_count support to the REST API will achieve two key objectives:

Enable Sorting by Comment Count in the REST API
Adding this feature will allow developers to sort posts by the number of comments directly in the REST API, enhancing the flexibility of post queries.

Integrate Comment Count Sorting into Gutenberg’s Latest Posts Block
Once the REST API is updated, this functionality can be leveraged to enhance the Latest Posts block in Gutenberg. The ability to sort posts by comment count was discussed in Gutenberg Issue #20046, and this feature was identified as missing in Revision 2 of the block.

This enhancement will provide users with a more dynamic way to display popular or highly engaged content while maintaining consistency between REST API capabilities and Gutenberg features.

Change History (2)

This ticket was mentioned in PR #8551 on WordPress/wordpress-develop by @vipulpatil.


5 weeks ago
#1

  • Keywords has-patch added; needs-patch removed

## Summary
This PR adds support for ordering posts by comment_count in the REST API by extending the orderby parameter in the get_collection_params method of the WP_REST_Posts_Controller class.

### Changes Made

  • Added comment_count to the list of allowed orderby parameters in get_collection_params.
  • Ensured that posts can now be sorted by the number of comments when querying via the REST API, providing a new way to retrieve popular or highly engaged posts.

### Why This is Needed:

  • Enables sorting posts by comment count directly from the REST API.
  • This enhancement lays the groundwork for integrating comment count sorting into Gutenberg’s Latest Posts block, addressing a feature gap mentioned in Gutenberg Issue #20046.

#2 @vipulpatil
5 weeks ago

@swissspidy Can you look at this ticket and the PR.
Also the Gutenberg issue mentioned in the ticket is https://github.com/WordPress/gutenberg/issues/20046
also mentioned here,
https://github.com/WordPress/gutenberg/issues/22002

Last edited 5 weeks ago by vipulpatil (previous) (diff)
Note: See TracTickets for help on using tickets.