Skip to content

Instantly share code, notes, and snippets.

@jhaus
Created December 4, 2010 23:13
Show Gist options
  • Save jhaus/728587 to your computer and use it in GitHub Desktop.
Save jhaus/728587 to your computer and use it in GitHub Desktop.
<?php
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
$categories = implode(",", $categories);
$XML = "<title>$title</title>".
"<category>$categories</category>".
$body;
$params = array('','',$username,$password,$XML,1);
$request = xmlrpc_encode_request('blogger.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_exec($ch);
curl_close($ch);
}
/*
This function requires that you have the php xmlrpc and curl modules enabled in php.ini. $title, $body, $username, and $password are pretty self-explanatory. $rpcurl is the XMLRPC server address for your wp install. It’s generally located at http://www.yourblog.com/xmlrpc.php . $categories is an array of the categories you want the post filed under, and defaults to category 1 which is Uncategorized in the default wordpress installation. You can most likely use either category numbers or names in this array.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment