I previously wrote about the first version of the WordPress JSON API here, but turns out, it’s not accurate anymore! Here’s an update of the code in that post; using this, you’ll be able to utilize the version two infrastructure of the API that is now in core WordPress 4.4. To use the core endpoints, you will still need to install the version two of the endpoint plugin. JSON API OVERVIEW Activate it and you now have a REST API for your site’s content. The plugin exposes your data in JSON format in the following content types: Posts Pages Media Custom Post Types Post Meta Revisions Comments Terms Users The response data is like what you would get in the WordPress loop, only the format is JSON. This allows you to display it in any way you wish. You can even filter the API calls in a similar fashion to the loop. Want to get your site’s posts? Simply send a GET request to url.com/wp-json/wp/v2/posts. Update user with ID 4? Send a POST request to url.com/wp-json/wp/v2/users/4. Return all posts with the search term “awesome”? GET url.com/wp-json/wp/v2/posts?filter[s]=awesome. It’s that easy. Some API calls require authentication, just like WordPress requires authentication to access wp-admin
Share This