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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.