Opened 6 years ago
Last modified 3 years ago
#43439 new defect (bug)
&_embed only embedding first 10 categories
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.9.4 |
Component: | REST API | Keywords: | needs-unit-tests has-patch |
Focuses: | rest-api | Cc: |
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)
Change History (13)
#1
follow-up:
↓ 2
@
6 years 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
@
6 years 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 likepost=
, 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:
↓ 4
@
5 years ago
@kadamwhite What sort of changes did you have in mind for making this more predictable?
#4
in reply to:
↑ 3
@
5 years ago
Replying to rmccue:
@kadamwhite What sort of changes did you have in mind for making this more predictable?
I would think the page
parameter 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).
#5
@
5 years 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.
#6
@
3 years ago
- Keywords needs-unit-tests added
A naive solution to this would be to always append per_page=100
in WP_REST_Server::embed_links()
. However that wouldn't be ideal for single routes, and we have no guarantee that collection routes actually implement their per_page
cap at 100
.
What we could do is inside of ::embed_links()
use the new ::match_request_to_handler()
and ::respond_to_request()
methods to reimplement ::dispatch()
but to first look if a per_page
arg is registered and if so, find it's maximum
value and apply it to the request.
@lpawlik are you interested in this one?
This ticket was mentioned in PR #672 on WordPress/wordpress-develop by lukaspawlik.
3 years ago
#8
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/43439
Allow _embed
to include all embedded object such as taxonomies, comments etc.
lukaspawlik commented on PR #672:
3 years ago
#9
@TimothyBJacobs @spacedmonkey this is an initial commit for https://core.trac.wordpress.org/ticket/43439. It seems to be solving reported issue however, I am concerned about the fact that it's using \WP_REST_Server::match_request_to_handler
that is modifying the state of passed request object, and the same method is called later via dispatch
method. Is it our concern that it's called second time? Do you have any other ideas to address this issue?
#10
@
3 years ago
Hey @lpawlik! Just following up on our conversation in Slack about how we could alleviate the duplicate matching issue.
Response showing it only coming back with 10 categories