Issuing POST requests

So, in the previous section, we saw how to copy an existing post from a remote site to our site. However, what if we wish to create a new post directly? For that purpose, we will need to issue a POST request using the WordPress HTTP API.

We will be making use of the wp_remote_post() function that can be used to issue POST requests. As you might already be aware, if you have ever developed for WordPress, this function will ask you for two parameters: a URL to make the POST request and a corresponding array of arguments to pass along with your request. Once again, we will get an array and work with it, or if an array is not given, we will force typecast it to an array form.

To authorize the object, we will use a code that looks ...

Get Learning WordPress REST API now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.