How to Create Posts in WordPress using REST_API?
Create Posts in WordPress using REST_API:
Creating posts in WordPress using the REST API involves making HTTP requests to the WordPress REST API endpoint for posts. Here is a basic guide on how you can do this:
Prerequisites:
-
1. WordPress Site: Ensure that you have a WordPress site with the REST API enabled.
2. Authentication: You might need to authenticate your requests. You can use basic authentication or OAuth depending on your requirements.
Steps to Create a Post:
1. Get Authorization Token (Optional):
2. Construct API Request:
# Example cURL request for creating a post (replace the values accordingly)
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_TOKEN" -d '{
"title": "Your Post Title",
"content": "Your post content.",
"status": "publish"
}' https://your-wordpress-site.com/wp-json/wp/v2/posts
3. Handle Response:
Example response:
{
"id": 123,
"title": {
"rendered": "Your Post Title"
},
"content": {
"rendered": "Your post content."
},
"status": "publish"
}