Make WordPress Core

Opened 7 years ago

Last modified 3 years ago

#41740 new enhancement

Add comment count to "replies" link in post responses

Reported by: rmccue's profile rmccue Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: REST API Keywords:
Focuses: Cc:

Description

Right now, you can preload comments using embedding with the linked "replies" resource. This is great, but there's no way to know whether you should try loading more. Fetching the resource directly would give you the total in the X-WP-Total header, but you lose this when embedding.

While this is generically a problem with the loss of headers from embedded resources, I don't think we really need a generic solution. Even when not embedding, a comment count is useful for archive display of a list of posts.

We should add the comment count (using wp_count_comments) to the "replies" link:

{
    "replies": [
        {
            "href": ".../wp/v2/comments?post=42",
            "embeddable": true,
            "count": 12,
        }
    ]
}

Attachments (1)

41740.diff (489 bytes) - added by wongalex 5 years ago.

Download all attachments as: .zip

Change History (3)

#1 @wongalex
5 years ago

I can look at this as my first bug :)

EDIT: Actually I looked through and it's just a one line change with the change being above haha. Ignore this.

Last edited 5 years ago by wongalex (previous) (diff)

@wongalex
5 years ago

#2 @TimothyBlynJacobs
3 years ago

A generic solution to this problem does exist, targetHints, which I would love for us to support. https://json-schema.org/draft/2019-09/json-schema-hypermedia.html#rfc.section.6.5.5

Note: See TracTickets for help on using tickets.