So if you are like many of the others out there struggling to automatically post to wordpress, I figured I’d give a little help today.  We’ve gone into a lot more detail inside the codebank, however, this should be enough to get anyone going.

(warning:  Wordpress does like to garble code and I’m to lazy to install a plugin to display it.  Watch out for quotes specifically)

// you have to include a path to a valid class-ixr.php file.  It’s included in every worpdress install.
include_once(‘/wp-includes/class-IXR.php’);

// if you aren’t working with multi site a blog id of zero is fine.

define(‘BLOG_ID’, 0);

// blog username and password
define(‘RPC_USERNAME’, ‘yourusername’);
define(‘RPC_PASSWORD’, ‘yourpassword’);
//  make sure the target blog has xml-rpc posting enabled under settings -> writting

$client = new IXR_Client(‘http://targetblog.com/xmlrpc.php’);

// O.k. we’ve got our client.

// what is our title, and the content of the post we want to send over.

$content['title'] = $title;
$content['categories'] = array($category);
$content['description'] =  $text;
// let’s post it……. false means it posts as a draft.  True means it posts as a live post.
$client->query(‘metaWeblog.newPost’, BLOG_ID, RPC_USERNAME, RPC_PASSWORD, $content, false);
echo $client->getResponse();

That’s it.  Just add in some error checking and go to town.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>