Opened 9 years ago
Closed 8 years ago
#40826 closed enhancement (fixed)
Allow items queried in batch via "slug" to maintain order
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.9 | Priority: | normal |
| Severity: | normal | Version: | 4.7.4 |
| Component: | REST API | Keywords: | |
| Focuses: | Cc: |
Description
When querying endpoints that have items, it is possible to pass an array of values to the slug param. This will filter the result set to only include slugs that match. This works for posts, pages, media, users, categories, and tags.
Often, the reason this is happening is so that a remote system can collect all relevant queries before sending one HTTP request that contains them all. This was formalized in #40027.
One caveat: the endpoints do not currently have a proper orderby value that ensures the items are returned in the same order they requested.
The best convention I could come up with is: orderby=slugs. Patch incoming.
This is essential for tools like Dataloader https://github.com/facebook/dataloader#batching
Attachments (5)
Change History (25)
This ticket was mentioned in Slack in #core-restapi by wonderboymusic. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#6
@
8 years ago
I don't want to bike shed the naming, so feel free to ignore. We have include for "order by the IDs passed", which is not past tense, so I'd be +1 for include_slugs.
This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.
8 years ago
#8
@
8 years ago
- Owner set to kadamwhite
- Status changed from new to accepted
I agree with @joehoyle on preferring include_slugs; I'll review this over the weekend and we should be able to get it in for 4.9. Thanks, @wonderboymusic!
#9
@
8 years ago
Added 40826.2.diff to change included_slugs to include_slugs, there should be no other differences between the two
This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by kadamwhite. View the logs.
8 years ago
#12
@
8 years ago
Fixed an issue with the previous patch I uploaded (had a stray test from another ticket), and added a @since note for the slugin addition to the WP_Term_Query constructor per feedback from @ocean90
#13
@
8 years ago
40826.4.diff is a refresh of 40826.3.diff that uses sanitize_title_for_query() rather than sanitize_title(). See the linked Slack discussion, as well as #19292 and [19444].
sanitize_title() is incorrectly used elsewhere in WP_Term_Query in a similar way. I'll open a separate ticket for that.
#17
@
8 years ago
- Keywords has-patch has-unit-tests commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
[41760] is causing Travis failures.
This change seems fine for a 4.8.x release, but I have a few specific points of feedback.
included_slugsis a better name for this neworderbyparameter. It's very similar to the existingincludefunctionality that deals with IDs, so the wordincludeshould appear in the name somewhere.slugsis too similar to the existingslugwhich just means "order by slug".WP_Term_Queryshould follow the naming convention of similar functionality in the rest of theWP_*_Queryclasses:fieldname__in(slug__inin this case).$this->assertPostsOrderedBy()helper to make for more precise tests and avoid having to create a bunch of test fixtures. With wider use, this should speed up the test suite pretty significantly.