Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to sync post edits on two sites. Test environment, not production. Single direction (site A to site B, but not backwards).

Basically I edit post at my local test stack and same post (part of test content set) at remote server should be updated with identical copy of resulting content.

I know that XML-RPC server is implemented in WordPress... But WordPress itself is not a XML-RPC client and I have no idea how easy would it be to make it into one (I am usually wary of XML-anything :)

So should I go with XML-RPC and implement client functionality or that is not worth the time and I should build custom form or something at remote server to catch changes?

share|improve this question
    
fetch_feed and using Simple Pie might be easier to implement. –  Chris_O May 1 '11 at 18:29
    
@Chris_O hmmm... but then I would need to (1) generate feed with all posts on site (2) scan every post in that feed for changes every time. (edit) Basically this is pull situation (B pulls from A) and I think I need push (A pushes to B) –  Rarst May 1 '11 at 18:35
    
It would work for catching new posts but not very efficient for checking for changes. –  Chris_O May 1 '11 at 18:39
    
@Chris_O there is no condition that I would edit newer posts, on the contrary - I can go back and edit some old post if I need to change deprecated test data. –  Rarst May 1 '11 at 18:41

1 Answer 1

up vote 11 down vote accepted

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();
}
share|improve this answer
    
Thank you, I had no idea it actually has client and quick Codex search missed it. –  Rarst May 2 '11 at 14:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.