How to Create Posts on a Remote WordPress Site Using WordPress REST API

The WordPress REST API makes it possible to send and receive data between any two WordPress environments or even between WordPress and external applications. In this guide, we’ll show you how to remotely create WordPress posts on another site using PHP and the WordPress REST API. Whether you’re managing one site or many, this guide helps developers and site admins to automate content flow between WordPress sites.

Solution: Create Posts on a Remote WordPress Site Using WordPress REST API

Here’s what you’ll learn:

  • Create a post on a live WordPress site from a local site using the REST API.

We’ll assume you have two sites:

  • Site A (Live Site): The destination where posts will be drafted
  • Site B (Localhost Site): The source from where you send or retrieve content.

Step 1: Enable Application Passwords on Site A (Live Site)

If you’re using WordPress 5.6 or higher, Application Passwords are built-in. If you’re on localhost and don’t see the Application Password field in their user profile, then add this code  to wp-config.php:

define( 'WP_ENVIRONMENT_TYPE', 'local' );
  1. Go to Users > Profile for the admin user.
  2. Scroll to “Application Passwords” section.
  3. Enter a name like Remote Post Creator and click “Add New Application Password”.
  4. Copy the generated password and keep it safe.

Step 2: Create a Post on the Live Site Using REST API

Create a file named send-post.php in the root folder of your local WordPress site (Site B).

<?php
$site_url = 'https://your-live-site.com'; // Replace with Site A URL
$username = 'admin_username'; // Admin username on Site A
$password = 'your_generated_app_password'; // App password (no spaces)

// Post content
$title = 'Post from Localhost';
$content = 'This post was created from a local site using REST API.';
$status = 'draft';

$data = [
    'title'   => $title,
    'content' => $content,
    'status'  => $status
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $site_url . '/wp-json/wp/v2/posts');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Basic ' . base64_encode("$username:$password")
]);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
} else {
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $body = json_decode($response);

    if ($http_code === 201) {
        echo '✅ Post created: ' . $body->title->rendered;
    } else {
        echo "\n❌ Failed to create post. HTTP Code: $http_code\n";
        print_r($body);
    }
}
curl_close($ch);
?>

Output

Now, go back to your live WordPress site (Site A) and navigate to Posts → All Posts. You’ll find that a new post has been created and saved as a draft using the WordPress REST API.