Opened 9 years ago
Closed 9 years ago
#38985 closed defect (bug) (fixed)
REST API: Some orderby parameters are broken
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.7 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | has-unit-tests has-patch commit dev-reviewed |
| Focuses: | Cc: |
Description
The orderby parameters id and slug are currently broken for posts. Since they don't map directly to WP_Query values, and there is no code to translate them, they don't do anything.
The include parameter works, but only if a list of IDs is specified via the include parameter. We should return an error for orderby=include without this parameter, like we do for orderby=relevance without search.
Attachments (3)
Change History (17)
This ticket was mentioned in Slack in #core-restapi by jnylen. View the logs.
9 years ago
#4
@
9 years ago
I guess we should remove id and slug given there's no simple way to achieve this with WP_Query.
#5
@
9 years ago
I haven't started on a patch for this yet.
It looks like we can just map id → ID and slug → name, like we already do for include → post__in. Presumably this is how it worked at one point.
I think this issue shows that we also need to add tests for the actual SQL - using the posts_orderby filter seems like a good way to achieve this. In fact if we have that in place then we could probably drop the testing of results lists altogether which can be a bit tricky.
I'm also wondering if there is similar breakage in the orderby parameters of other endpoints.
@
9 years ago
Adds an error when include orderby is specified without an include parameter. The id and slug orderby parameters now properly map to their correct fields ID and post_name. There may still be more problems surrounding orderby, but this addressed the ones reported in this ticket.
This ticket was mentioned in Slack in #core-restapi by chopinbach. View the logs.
9 years ago
@
9 years ago
Adds an error when include orderby is specified without an include parameter. The id and slug orderby parameters now properly map to their correct fields ID and post_name. There may still be more problems surrounding orderby, but this addressed the ones reported in this ticket. This is a slightly cleaner approach, and makes future maintenance of the orderby params simpler.
This ticket was mentioned in Slack in #core by helen. View the logs.
9 years ago
#9
@
9 years ago
- Focuses performance added
- Keywords needs-refresh added
- Owner set to jnylen0
- Status changed from new to assigned
We are in a string freeze for 4.7 and cannot introduce a new error message.
I see two options here:
- We ignore the
includeorderbyvalue if the request does not include the relatedincludeparameter. - We remove support for the
'orderby' => 'include'for 4.7.
I would like to do Option #1 if possible, but we are running out of time here folks.
#11
@
9 years ago
- Keywords needs-refresh removed
Option 3: reuse an existing error message for 4.7 and clean it up in 4.8.
Done in 38985.3.diff; also renamed $orderby_possibles → $orderby_mappings to match $parameter_mappings in the same file.
#12
@
9 years ago
- Keywords commit dev-feedback added
I'm cool with 38985.3.diff, there's nothing insane that will cause everything to explode.
@jnylen0
If you aren't already prepping a patch I can do a patch for it. It should be a lot cleaner than my last attempt.