WordPress Rest API v2 Order by Random

order-by-random

To order the results coming back from wp api we can use the filter:
rest_{#post_type}_collection_params.

For example, if your post type is review:


add_filter( 'rest_review_collection_params', 'prefix_rest_orderby_rand', 10, 1 );
function prefix_rest_orderby_rand( $params ) {
    $params['orderby']['enum'][] = 'rand';
    return $params;
}

Ordering by random may impact performance.