WordPress XML-RPC: wp.getTags

Using wp.getUsersBlog, you can find the blogs corresponding to the user whose “username” is sent. Now with the response, you can get the blogid. The tags corresponding to the blog can be found using wp.getTags.

It takes three parameters

  1. BlogID (One of the result parameters in wp.getUsersBlogs)
  2. Username
  3. Password

This is shown here

<?php

$BLOGURL = "http://localhost/wordpress";
$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.getTags request which takes on three parameters
   blogid,
   username,
   password*/
  $request = xmlrpc_encode_request("wp.getTags",
    array(1,$USERNAME, $PASSWORD));

  /*Making the request to wordpress XMLRPC of your blog*/
  $xmlresponse = get_response($BLOGURL."/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*/
    print_r($response);
  }
echo "n";
?>

On executing it gives the following response

<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
      <value>
        <array><data>
  <value><struct>
  <member><name>tag_id</name><value><string>5</string></value></member>
  <member><name>name</name><value><string>Blogging</string></value></member>
  <member><name>count</name><value><string>1</string></value></member>
  <member><name>slug</name><value><string>blogging</string></value></member>
  <member><name>html_url</name><value><string>http://localhost/wordpress/?tag=blogging</string></value></member>
  <member><name>rss_url</name><value><string>http://localhost/wordpress/?feed=rss2&amp;amp;tag=blogging</string></value></member>
</struct></value>
  <value><struct>
  <member><name>tag_id</name><value><string>6</string></value></member>
  <member><name>name</name><value><string>Wordpress</string></value></member>
  <member><name>count</name><value><string>1</string></value></member>
  <member><name>slug</name><value><string>wordpress</string></value></member>
  <member><name>html_url</name><value><string>http://localhost/wordpress/?tag=wordpress</string></value></member>
  <member><name>rss_url</name><value><string>http://localhost/wordpress/?feed=rss2&amp;amp;tag=wordpress</string></value></member>
</struct></value>
</data></array>
      </value>
    </param>
  </params>
</methodResponse>

The response gives the tag id, tag name, count, the feed url. The response content can be clearly understood by their names

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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