Post on wordpress remotely with xmlrpc in PHP
anoopsachari | May 01, 2010 | Comments 9
Recently i have been working on some wordpress blogs that required frequent addition of post . Coding an automated post generator was not a big task but didn’t know how to post it using php . After a research found that we can post on wordpress remotely using xmlrpc .
I am sharing you the php function which i used in my project . As the code use cURL it should be enabled and activate xmlrpc on wordpress admin panel .
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);
}
Usage :
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
You have done ! Comment me if you need any help .
About the Author: a holistic web developer , movie buff and technical blogger from queen of arabian sea.







Hi,
This post is too useful!
I am from Allepey
Happy to see a malayali
I need your help can you give your gmail address
Thanks
@balaji contact me at anoop.s.achari@gmail.com
Thanks!
I have Mailed you!
hi Can you help me to access webserver using xmlrpc to add post on other server
@nice . ys sure tell me
Hi Ya.
nice stuff, i have specific requirement where i want to post to specific categories ? How your script handles that ?
thanks,
Jackie
@jackie
change the value of $category when you call the fuction .
like :
wpPostXMLRPC($title,$body,$rpcurl,$username,$password,x);
replace x with 1,2,3 … etc .
Hi,
I want to post into multiple wordpress blog using XMLRPC at once.Is it possible with one click.if yes then how can I do
How do you do posting with tags and custom fields by using this function?