WP REST API: Modifying the JSON Response

The WordPress API includes several endpoints you can use to read information from the database and use the data for different purposes. In this blog post we will get use of the /wp-json/wp/v2/posts endpoint, which is something like running a WP_Query. It works using the four most common HTTP methods – GET, POST, PUT and DELETE, for which you will need to be authorized to work with.

* Note that you will need to install the WP REST API plugin.

Because we mostly don’t need and use all the information, there is a way to manipulate the JSON response. WP API provides us with a filter called rest_prepare_posts which we can use for adding and removing fields (data). So, lets jump into some examples.
Continue reading “WP REST API: Modifying the JSON Response”