1. Go to this page and download the library: Download tombroucke/wp-sync-posts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tombroucke / wp-sync-posts example snippets
use \Otomaties\WpSyncPosts\Syncer;
$syncer = new Syncer('post');
$response = wp_remote_get('https://example.com');
$externalPosts = wp_remote_retrieve_body($response);
foreach ($externalPosts as $externalPost) {
$args = [
'post_title' => $externalPost->title(),
'post_content' => $externalPost->content(),
'post_date' => gmdate('Y-m-d H:i:s', $externalPost->createdTime()),
'post_status' => 'publish',
'meta_input' => [
'external_id' => $externalPost->id(),
'other_meta' => $externalPost->otherMeta(),
],
'media' => [
[
'key' => false,
'featured' => true,
'url' => $externalPost->thumbnail()->url(),
'date_modified' => gmdate('Y-m-d H:i:s', $externalPost->createdTime()),
'group' => 'synced_images' // image IDS will be stored in the synced_image meta field
],
],
];
$existingPostQuery = [
'by' => 'meta_value', // id, meta_value
'key' => 'external_id', // Only if 'by' => 'meta_value'
'value' => $externalPost->id(), // Unique value to identify this post
];
$syncer->addPost($args, $existingPostQuery);
}
$syncer->execute();