[wp-trac] [WordPress Trac] #38693: REST API: Audit `orderby` params and add any others
WordPress Trac
noreply at wordpress.org
Tue Nov 29 03:46:44 UTC 2016
#38693: REST API: Audit `orderby` params and add any others
-------------------------+------------------------------
Reporter: jnylen0 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by ChopinBach):
The "rest_{$this->post_type}_collection_params" filter can be used to add
in additional `orderby` values. To add random, you could hook in like
this:
{{{#!php
<?php
add_filter( 'rest_post_collection_params',
'my_prefix_add_rest_orderby_params', 10, 1 );
function my_prefix_add_rest_orderby_params( $params ) {
$params['orderby']['enum'][] = 'rand';
return $params;
}
}}}
If there is a consensus on what should be added as supported defaults, I
can make a patch. The hook is already available to use.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38693#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list