intuitive-custom-post-order
intuitive-custom-post-order copied to clipboard
Integrate with WP API
It would be very useful to have support for post order when getting posts with the WP API
Some technical details I've found along the way that I hope can help implement this issue:
I've found this code in WP API's class-wp-rest-posts-controller.php, line 1636:
if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) { $params['orderby']['enum'][] = 'menu_order'; }
I'm not sure, but I think it means if all post-types support 'page-attributes', then menu_order would be supported by orderby.
So i think calline add_post_type_support() somewhere, on all post type (all?), would do the trick.
As a work-around for this I am doing:
add_filter( "rest_<custom_post_type>_query", function( $args, $request )
{
$args['orderby'] = 'menu_order';
return $args;
}, 10, 2 );
So if you're filtering pages you should be able to use rest_page_query
Reference: http://wordpress.stackexchange.com/a/225718/63153