Post on WordPress Remotely with XMLRPC Using PHP

A small php function to post on wordpress remotely using xmlrpc. As the code use cURL it should be enabled and activate xmlrpc on wordpress admin panel. I haven't used or tried it yet, but I am going to need it soon.

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('wp.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);
}

Useage:

wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1));

All parameter that we pass are self explanatory except $rpcurl . $rpcurl – is the path to file xmlrpc.php of your blog , mostly it would be on root of your blog . eg : http://www.yourdomain.com/xmlrpc.php

Src: http://www.achari.in/post-on-wordpress-remotely-with-xmlrpc-in-php

About Keiron

Web Developer based in the UK. Click here if you want to work with me