There are many ways to publish WordPress blog post. You can publish from the WordPress admin interface, you can publish via email and also you can publish it via XML-RPC. So what is XML-RPC? XML-RPC is a remote procedure call (RPC) protocol which uses XML to encode its calls and HTTP as a transport mechanism. Which mean we can call the WordPress procedure remotely. And this will make WordPress easily integrate with other system.
To enable publish via XML-RPC in WordPress follow these steps:
- Login to your WordPress admin
- Go to Settings > Writing > Remote Publishing
- Enable Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols. checkbox.
To try it you can use this code below:
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8') { $title = htmlentities($title,ENT_NOQUOTES,$encoding); $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding); $content = array( 'title'=>$title, 'description'=>$body, 'mt_allow_comments'=>0, // 1 to allow comments 'mt_allow_pings'=>0, // 1 to allow trackbacks 'post_type'=>'post', 'mt_keywords'=>$keywords, 'categories'=>array($category) ); $params = array(0,$username,$password,$content,true); $request = xmlrpc_encode_request('metaWeblog.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); $results = curl_exec($ch); curl_close($ch); return $results; }
To test it:
$title="Lorem ipsum"; $body="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vestibulum pharetra mi quis rhoncus. Mauris lacinia neque id lacus lobortis a dictum augue molestie. Proin ut elit velit, in faucibus neque. Aliquam libero odio, bibendum non tempor eu, sodales vel felis."; $rpcurl="http://your_wordpress_blog_url/xmlrpc.php"; $username="Wordpress admin username here"; $password="Wordpress admin password here"; $categories="category name here"; echo wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories,'');
With this XML-RPC it is possible for you to write article offline and then publish it with XML-RPC. Here some good tools for that:
- Windows Live Writer (Windows Only)
- BlogJet (Windows Only)
- Blogo (Mac Only)
- MarsEdit (Mac Only)
- BloGTK (Linux Only)
- Scribefire (Firefox Add-on / All platform)
- Flock (Web Browser / All platform)
van, klo pakai .net ada ga?? mau bikin something nih..
sama aja caranya lek. tinggal kamu httpwebrequest dan tembak ke xmlrpc nya.
Hi,
thanks for this trick, I will try it as soon as I get a chance. In the meantime, two questions:
1) does it work with https, to not send the password in clear over the net?
2) is this "future-proof"? I mean, how much is it likely that this function won't work anymore in future versions of wordpress? Reason I'm asking is I'm evaluating wordpress for my next website, and ability to update it from the command line may be what makes the difference, but only if I'm sure this will continue to be available.
Thanks,
Marco
Hi Marco
here is the answer for your question:
1. Yes it works with HTTPS, but you need to include that option in Curl. Curl support secure connection
2. WordPress will keep this feature, as it's ability to work with third party application. Ping back using WordPress XMLRPC feature as well.
Wordpress is powerful CMS, but it can kill your server if it is not carefully configured and optimized.
Ivan, thanks very much for the prompt answer, this is good news. May I ask you, at this point, suggestions and links to read to avoid the risk you mention in last sentence:
"Wordpress… can kill your server if it is not carefully configured and optimized"
WordPress is a powerful CMS, but it is like a double edge sword. It also resource heavy CMS. When you are using wrong plugin,it can make your server fully load. See my article about optimizing high traffic wordpress blog:
http://ezinearticles.com/?Steps-To-Optimize-a-High-Traffic-WordPress-Blog&id=4992584
"How to submit forms using cURL over SSL" would have been better… 🙁
Curl does support SSL. See this PHP manual: http://php.net/manual/en/book.curl.php
I'm new to this, and I keep getting this error:
Fatal error: Call to undefined function xmlrpc_encode_request()
I've enabled xmlrpc in the admin panel. I'm on my own server so I may be missing some essential modules or settings. Thank you.
I am expereincing a similar situation.. same error message yet xmlrpc is enabled.. Did you sort this out?
Hey
I am using this script and it works perfectly. However, it sometimes returns false even tho the post is added to the blog.
Do you know why this happens?
– Stian
Hi Stian,
it could be many things, how about your internet connection? or how many traffic your blog is, because sometimes when the server is busy, it would return timeout.
Good one, makes to understand the remote publishing to WP easy
I'm not getting a response from the CURL so $results is empty… I wanted to verify that a post was made and get the post # – any ideas?
have you enable Remote Publishing in WordPress?
Bos Ivan terimakasih banyak code nya, saya masih belum berhasil kalo kita mau multiple category, ada petunjuk?
try
$category = array('category1', 'category2');
Hi, i want to insert multiple categories from outsite the function but it doesnt work.
$category = "'Musicians','Comedians'";
If i add only one category its working
$category = "Musicians";
But multiple i don't know how to write this line.
try $category = array("Musicians", "Comedians");
Better explained here http://www.hurricanesoftwares.com/wordpress-xmlrpc-posting-content-from-outside-wordpress-admin-panel/
Great article Ashish, thanks.
the above code is not executed correctly please make sure
Hi,
just for completeness: due mainly to personal preference, eventually I figured out another way to post to WordPress from the command line. Here it is:
http://freesoftware.zona-m.net/how-to-post-content-to-a-wordpress-blog-from-the-command-line/
HTH,
Marco
Thanks Marco.
Hi Ivan,
I'm using XML-RPC posting, but in the end my posts appear with broken html tags and it's painful because my links end broken. The problem appears to be in my hosting company, but they can't resolve my problem.
What can I do solve this issue?
Thanks!
hi,i am trying to post the values such as title,description and category to a web site using xml-rpc.But it post two values title and description from xml file …..can you tell me coding post with category values????//please
hi,i am trying to post the values such as title,description and category to a web site using xml-rpc.But it post two values title and description from xml file …..can you tell me coding post with category values????//please