Join Morten Rand-Hendriksen for an in-depth discussion in this video What is the WordPress REST API?, part of WordPress: REST API.
That's quite a mouthful, so here's the English translation. The WordPress REST API is a new way of accessing the data WordPress provides, without having to go through a theme, or an RSS feed, or XML-RPC. And when I say "accessing," I don't just mean getting the data to read. With the REST API, you'll be able to create, read, update, and delete content in the WordPress database without interacting with WordPress directly. And this opens up a whole new world of opportunities.
Let me explain. Up until now, if you wanted to read a WordPress post or page, you had to use a WordPress query in PHP, typically through a WordPress theme. The theme would use the WordPress templating engine and hierarchy, otherwise known as a theme, to output the post, or page, or other content you requested through the address bar on your browser. This setup has some severe limitations. If, for example, you wanted the content from your WordPress site to appear in a mobile app, you'd have to either build a custom PHP application to do it, or pass the data through antiquated protocols.
And that's just the tip of the iceberg. The WordPress REST API also allows us to access and edit the data in the database without going through WordPress admin. Now, before you get worried, this is only possible if you have the right security credentials, so your data is not at risk. But, it means we can now build new interfaces for creating content with WordPress. Just think about that for a minute. WordPress without the WordPress admin panel. In this course, you'll build a foundational understanding of the WordPress API, what it is, how it works, and how we interact with it.
We'll spend some time digging into the details of the API to understand its structure, and build three practical examples that showcase how to interact with the API and read-only mode to extend its functionality, add RESTful data to a normal PHP-based WordPress theme, and build a simple, headless application that uses WordPress as a data source.
- Using a REST client to communicate with a REST API
- Reviewing available routes, endpoints, and arguments
- Adding custom post types and taxonomies
- Altering the API response
- Using PHP for resiliency
- Passing info using wp_localize_script()
- Setting up a REST API request through AJAX
- Outputting selected post data to the front end
- Formatting post data to match a theme
- Triggering AJAX for an infinite scroll effect
- Using AJAX to load subsequent responses