Working with WordPress XMLRPC- Simple Example

How often do you go to to update your blogs? Or you may have a blog using the wordpress blogging platform. You often desired to have some editors which help you to directly blog from your desktops without going to the browser. For this purpose, wordpress also provides the XMLRPC interface. Using the XMLRPC interface, developers can make wordpress clients which help anybody to post from their desktop clients without going to the browser. WordPress XMLRPC supports many other APIs like the blogger API, MetaWebLog apart from its own functions.

Let’s take a simple example which makes of the function wp.getUsersBlogs(). Here we’re going to show a simple PHP program. Note you must substitute your USERNAME and PASSWORD


$USERNAME = "admin";
$PASSWORD = "check";

function get_response($URL, $context) {
 if(!function_exists('curl_init')) {
 die ("Curl PHP package not installedn");

 /*Initializing CURL*/
 $curlHandle = curl_init();

 /*The URL to be downloaded is set*/
 curl_setopt($curlHandle, CURLOPT_URL, $URL);
 curl_setopt($curlHandle, CURLOPT_HEADER, false);
 curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
 curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);

 /*Now execute the CURL, download the URL specified*/
 $response = curl_exec($curlHandle);
 return $response;

  /*Creating the wp.getUsersBlogs request which takes on two parameters
   username and password*/
  $request = xmlrpc_encode_request("wp.getUsersBlogs",
    array($USERNAME, $PASSWORD));

  /*Making the request to wordpress XMLRPC of your blog*/
  $xmlresponse = get_response("http://localhost/wordpress/xmlrpc.php", $request);
  $response = xmlrpc_decode($xmlresponse);

  if ($response && xmlrpc_is_fault($response)) {
    trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
  } else {
    /*Printing the response on to the console*/
echo "n";

Now let’s execute this program from the browser or console

$ php wp.getUserBlogs.php

If you get the following ERROR, you must refer the post on enabling WordPress XMLRPC

<?xml version="1.0"?>
          <value><string>XML-RPC services are disabled on this blog.  An admin user can enable them at http://localhost/wordpress/wp-admin/options-writing.php</string></value>

After enabling wordpress XMLRPC services, you will get the following response

<?xml version="1.0"?>
  <member><name>blogName</name><value><string>Wordpress Test blog</string></value></member>

Check more on the return value of wp.getUserBlogs. You can learn more about wordpress XMLRPC.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s