Retrieve posts per customised order through JSON REST API

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page


The JSON REST API service, fully implemented into WordPress since 4.7, provides a great way for other applications to connect. This is a huge step forward, as it can communicate and exchange data regardless of what languages an external program uses.

The API support a bunch of endpoints to cover pretty much all existing data. A full list can be found at https://developer.wordpress.org/rest-api/reference/

Post retrieval through the API can be done by invoking the “posts” endpoint as follow:


curl -X OPTIONS -i https://example.com/wp-json/wp/v2/posts

The full list of supported arguments can be checked at https://developer.wordpress.org/rest-api/reference/posts/#list-posts

To retrieve the list of posts in an order predefined through a custom sort the orderby argument need to be passed through along the API call:


curl -X OPTIONS -i https://example.com/wp-json/wp/v2/posts?categories=1&orderby=menu_order&order=asc

The above return all posts which belong to category id 1, using the order defined in the sort list.