WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 13 months ago

#43439 new defect (bug)

&_embed only embedding first 10 categories

Reported by: manyourisms Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9.4
Component: REST API Keywords: needs-patch
Focuses: rest-api Cc:
PR Number:

Description

Normally our posts don't have more than 10 categories, but I did notice that when adding more than 10 to a post, a query using &_embed still only embedding the first 10. After searching through the class-wp-rest-server.php code, it doesn't seem like that should be the case, but alas! I'm too unfamiliar with how it is building the links for a post behind the scenes, but surely it must be happening there if I was to guess.

Hitting the category link href at wp-json/wp/v2/categories?post=<postId> also only returns 10 categories.

Attachments (2)

10-categories.PNG (31.6 KB) - added by manyourisms 21 months ago.
Response showing it only coming back with 10 categories
many-categories.PNG (28.6 KB) - added by manyourisms 21 months ago.
Edit post page showing much more than 10 categories for the post.

Download all attachments as: .zip

Change History (7)

@manyourisms
21 months ago

Response showing it only coming back with 10 categories

@manyourisms
21 months ago

Edit post page showing much more than 10 categories for the post.

#1 follow-up: @kadamwhite
21 months ago

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

Hitting the category link at wp-json/wp/v2/categories?post=<postId> and receiving 10 responses is expected; collections maintain standard pagination behavior when using query parameters like post=, so you can see the next page of responses with &page=2.

Only permitting up to 10 records to be embedded, however, is unexpected. Good catch! The origin of the issue appears to be that we use the REST API internally to embed links collections, and these requests obey the REST API's standard 10-post collection response limit. I'd definitely consider changing this to work in a more predictable way.

#2 in reply to: ↑ 1 @manyourisms
21 months ago

Wunderbar! Thanks for the clarification on the categories endpoint, sorry to have missed that.

Replying to kadamwhite:

Hitting the category link at wp-json/wp/v2/categories?post=<postId> and receiving 10 responses is expected; collections maintain standard pagination behavior when using query parameters like post=, so you can see the next page of responses with &page=2.

Only permitting up to 10 records to be embedded, however, is unexpected. Good catch! The origin of the issue appears to be that we use the REST API internally to embed links collections, and these requests obey the REST API's standard 10-post collection response limit. I'd definitely consider changing this to work in a more predictable way.

#3 follow-up: @rmccue
20 months ago

@kadamwhite What sort of changes did you have in mind for making this more predictable?

#4 in reply to: ↑ 3 @manyourisms
18 months ago

Replying to rmccue:

@kadamwhite What sort of changes did you have in mind for making this more predictable?

I would think the _embed would apply only to the main resource you are requesting, IE posts in this case. I would expect all embeds for those 10 resources to come back (unless there was an additional paging param for the embeds for some reason).

Version 0, edited 18 months ago by manyourisms (next)

#5 @kadamwhite
13 months ago

I would also feel like we'd get back all embeds. If I have a resource that includes a link to that resource's categories, I would expect to be able to follow it and get a comprehensive list.

This obviously raises the question of how to handle situations (rare, but they happen) where one post may have 100+ tags or categories. I think to start we should hard-cap in that edge-case, but otherwise return a full list when embedded.

Note: See TracTickets for help on using tickets.