Created
December 4, 2010 23:13
-
-
Save jhaus/728587 to your computer and use it in GitHub Desktop.
WP Remote Post via: http://www.nickycakes.com/post-to-wordpress-remotely-with-xmlrpc-in-php/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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