WordPress already has a XML-RPC client class implemented. It’s in the same file as the server part: class-IXR.php
located in wp-includes
.
The following code will generate a new post. You could wrap this in a function and attach it to the save_post
/update_post
action hook. To sync both parts, you could check for the post-slug or submit the same post-id to the post in the second blog.
$rpc = new IXR_Client('http://second-blog-domain.tld/path/to/wp/xmlrpc.php');
$post = array(
'title' => 'Post Title',
'categories' => array('Category A', 'Category B'),
'mt_keywords' => 'tagA, tagB, tagC',
'description' => 'Post Content',
'wp_slug' => 'post-slug'
);
$params = array(
0,
'username',
'password',
$post,
'publish'
);
$status = $rpc->query(
'metaWeblog.newPost',
$params
);
if(!$status) {
echo 'Error [' . $rpc->getErrorCode() . ']: ' . $rpc->getErrorMessage();
exit();
}