WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 7 months ago

#39037 new enhancement

Should REST API support multiple orderby values?

Reported by: ChopinBach Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.6.1
Component: REST API Keywords:
Focuses: Cc:
PR Number:

Description

WP_Query features the ability to query by multiple orderby parameters as well as independent orderby parameters (https://core.trac.wordpress.org/ticket/17065). The API does not have this ability yet. I looked through GitHub issues to find any discussion regarding this and could not find any. Should the REST API also support multiple orderby parameters or is that deemed to be plugin territory?

Change History (4)

#1 @jnylen0
3 years ago

What would it take to support this as a feature of the API?

Is it possible to make this work via existing filters? (This would also be a useful exercise to document adding orderby parameters via filters and determining whether there is anything left to be fixed there - see ticket:38693#comment:22 for a simpler case which we haven't tried yet)

#2 follow-up: @jnylen0
3 years ago

Another question: do other object types (WP_Comment_Query etc) support this?

#3 in reply to: ↑ 2 @ChopinBach
3 years ago

Replying to jnylen0:

Is it possible to make this work via existing filters?

Implementing multiple orderby values is not too difficult to implement. Doing the independent variation where some fields are ASC and some DESC would be considerably harder to put into the API. I am pretty sure you can do both by using multiple filters in the API.

Another question: do other object types (WP_Comment_Query etc) support this?

From a quick look, it appears that only the standard WP_Query object supports multiple and independent orderby parameters.

#4 @ChopinBach
3 years ago

WP_User_Query does support multiple orderby parameters.

Note: See TracTickets for help on using tickets.