WordPress Sync Post With Other Site Plugin Alternative

The "Sync Post With Other Site" WordPress plugin enables an option to sync your post directly to another site. Here is the official description:

If you run multiple websites and want to synchronize them automatically and securely for specific post operations, then Sync Post With Other Site is the plugin to use.

Sync Post With Other Site

I happen to need a wordpress plugin to sync content between sites. Unfortunately, "Sync Post With Other Site" doesn't work recently! And many people including me have met some problems:

Didn't work. In fact: received a critical error when trying to sync a page update Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /wp-content/plugins/sync-post-with-other-site/includes/sps_sync.class.php:126 Stack trace: #0 /wp-includes/class-wp-hook.php(308): SPS_Sync->sps_save_post() #1 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #2 /wp-includes/plugin.php(517): WP_Hook->do_action() #3 /wp-includes/post.php(4717): do_action() #4 /wp-includes/post.php(4819): wp_insert_post() #5 /wp-admin/includes/post.php(426): wp_update_post() #6 /wp-admin/post.php(227): edit_post() #7 {main} thrown in /wp-content/plugins/sync-post-with-other-site/includes/sps_sync.class.php on line 126 Downgrading to PHP 7.4 solved the critical error but then no actual syncing took place.

Jamie VanRaalte March 30, 2023

Tested on 3 domains and nothing happens whatsoever!

Janoshke January 18, 2023

So I started looking for an alternative of Sync Post With Other Site And found Simple WordPress Crossposting. But that is too expensive!

So I decided to write a new Sync Post With Other Site Plugin.

WordPress Sync Post With Other Site Plugin Alternative

WordPress Sync Post With Other Site Plugin Alternative

My plugin uses wordpress api for posts sync. It enables wordpress to sync posts between sites. Since my post publish process is like this:

When I publish a post on wordress 1 and I need it to automatically send that post to wordpress 2. What's more, the publish status needs to be "publish" as well.

If your workload is like mine, feel free to read the following steps.

Here’s how to sync posts in wordpress for free:

Step1, on wordpress 2(destination site) you need to install a plugin named "WordPress REST API Authentication" and activate it.

WordPress REST API Authentication

Step2, on your desktop, create a folder named "WP Post Sync" .

In the folder, create a file named "index.php" and here is the code snippet to put in that file:

<?php
/*
Plugin Name: WP Post Sync
Plugin URI: https://googoler.com/
Description: Sync WordPress posts between two sites via REST API
Version: 1.0
Author: Googoler
Author URI: https://googoler.com
*/

function wp_post_sync_publish_post( $post_ID, $post ) {
    // Only sync posts that are published
    if ( $post->post_status == 'publish' ) {
        $title = $post->post_title;
        $content = $post->post_content;

        $data = array(
            'title' => $title,
            'content' => $content,
            'status' => 'publish',
            'type' => 'post'
        );

        $url = 'https://wordpress2.com/wp-json/wp/v2/posts'; // Replace with the URL of your target site
        $args = array(
            'headers' => array(
                'Content-Type' => 'application/json',
                'Authorization' => 'Basic username:password' // Replace with your REST API authentication details
            ),
            'body' => json_encode( $data )
        );

        // Send a POST request to the target site's REST API to create the post
        wp_remote_post( $url, $args );
    }
}
add_action( 'publish_post', 'wp_post_sync_publish_post', 10, 2 );
?>

Make sure to change the code in red:

$url = 'https://wordpress2.com/wp-json/wp/v2/posts';

replace wordpress2.com with your destination site domain

Then this line:

'Authorization' => 'Basic username:password' 

You should not just input username:password there, because it should be encoded. You can use this tool to encode it

so if your username and password is abcd and 1234 (abcd:1234) will become YWJjZDoxMjM0, so the final code will be:

'Authorization' => 'Basic YWJjZDoxMjM0' 

Step3, zip the folder into WP Post Sync.zip and now you can upload it to your first wordpress site (wordpress1).

Activate it and it will work as expected. When you publish a post on wordpress1, it will automically be synced to wordpress2.

If you've got any questions, feel free to leave me a comment.