Let’s assume it stores the custom order into the menu_order
column in the wp_posts
table.
If you mean the hierarchical page
post type (supports page-attributes) then one can order with the query variables:
/wp-json/wp/v2/pages/?orderby=menu_order&order=asc
If you mean the post
post type with:
/wp-json/wp/v2/posts/
there’s a way using the rest_{post_type}_query
filter:
/**
* Set orderby to 'menu_order' for the 'post' post type
*/
add_filter( "rest_post_query", function( $args, $request )
{
$args['orderby'] = 'menu_order';
return $args;
}, 10, 2 );
We might want to restrict this further. Skimming through the WP_REST_Request
class we can see there’s a handy get_param()
public method that we could make use of:
/**
* Support for 'wpse_custom_order=menu_order' for the 'post' post type
*/
add_filter( "rest_post_query", function( $args, $request )
{
if( 'menu_order' === $request->get_param( 'wpse_custom_order' ) )
$args['orderby'] = 'menu_order';
return $args;
}, 10, 2 );
where we activate it through a custom wpse_custom_order
parameter:
/wp-json/wp/v2/posts/?wpse_custom_order=menu_order&order=asc
There’s also the dynamically generated rest_query_var-orderby
filter.