A Zend Framework service class for the WordPress XML-RPC api
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Similar to Zend_Service_Twitter, this service allows you to easily consume a WordPress blog's content via WordPress' XML-RPC gateway.


Zend_Service_Wordpress tries to keep a small, consistent API that returns results based on the context of the call.

For example, you can call getCategories() on both the ZendX_Service_Wordpress and ZendX_Service_Wordpress_Post.

With the first, you'll receive all of the categories for the entire blog while the latter returns only the categories attached to that post (as ZendX_Service_Wordpress_Category objects, of course).

Connect to your blog:

// ZendX_Service_Wordpress(XMLRPC_URL, USERNAME, PASSWORD[, CACHE = true ])
// Caching assumes that categories/posts/tags aren't being edited during the lifetime
// or the page rendering
$wordpress = new ZendX_Service_Wordpress('http://wordpress-site.com/xmlrpc.php', 'username', 'password');

// Get default blog
$blog = $wordpress->getBlog();
// or a specific blog by id:
$blog = $wordpress->getBlog(0)

Get various site information:

echo $blog->getTitle();         // My WordPress Blog
echo $blog->getDescription();   // Another WordPress Blog
echo $blog->getUrl();           // http://wordpress-site.com/
echo $blog->getLink();          // <a href="http://wordpress-site.com" title="My WordPress Blog">My WordPress Blog</a>
// etc...

List all tags:

foreach ($blog->getTags() as $tag) {
    // Uses ZendX_Service_Wordpress_Tag object
    echo sprintf('<a href="%s">%s</a>', $tag->getUrl(), $tag);
    // or
    echo $tag->getLink();

List all categories:

foreach ($blog->getCategories() as $category) {
    // Uses ZendX_Service_Wordpress_Category object
    echo sprintf('<a href="%s">%s</a>', $category->getUrl(), $category);
    // or
    echo $category->getLink();

Get recent posts

foreach ($blog->getRecentPosts(10) as $post) {
    // Uses ZendX_Service_Wordpress_Post object
    echo $post->getLink();

Get post information

echo $post->getTitle();
echo $post->getExcerpt();

echo $post->getBody();
// or
echo $post  // __toString method calls `getBody()`

foreach ($post->getTags() as $tag) {
    echo $tag->getLink();

foreach ($post->getCategories() as $category) {
    echo $category->getLink();

Unit Testing

You can perform unit testing by installing PHPUnit (I recommend the manual install) and doing...

# cd zend-service-wordpress/tests
# phpunit

Hopefully, you should see something like:

phpunit PHPUnit 3.3.9 by Sebastian Bergmann.


Time: 18 seconds

OK (7 tests, 28 assertions)

If you want to run a specific test, simply run:

# phpunit --filter testTags.

However, if you want to run all tests for Wordpress in general (or perhaps a subset of tests for just Blog, Post, Category, Author, or Tag), simply run:

# phpunit --group Wordpress
# phpunit --group Blog
# phpunit --group Post

Code Sniffing

You can run PHP CodeSniffer to ensure your markup follows the Zend standard by running:

# cd zend-service-wordpress
# phpcs --report=full --standard=Zend .