wordpress rest api orderby random

Solutions on MaxInterview for wordpress rest api orderby random by the best coders in the world

showing results for - "wordpress rest api orderby random"
Lino
20 Jan 2018
1<?php
2 
3/**
4 * Add `rand` as an option for orderby param in REST API.
5 * Hook to `rest_{$this->post_type}_collection_params` filter.
6 *
7 * @param array $query_params Accepted parameters.
8 * @return array
9 */
10function add_rand_orderby_rest_post_collection_params( $query_params ) {
11	$query_params['orderby']['enum'][] = 'rand';
12	return $query_params;
13}
14add_filter( 'rest_post_collection_params', 'add_rand_orderby_rest_post_collection_params' );
15