PHPackages                             comodojo/wpapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. comodojo/wpapi

AbandonedArchivedLibrary[API Development](/categories/api)

comodojo/wpapi
==============

Wordpress XML-RPC API wrapper

1.0.2(10y ago)141[1 issues](https://github.com/comodojo/wpapi/issues)MITPHPPHP &gt;=5.3.0CI failing

Since Jul 11Pushed 10y ago4 watchersCompare

[ Source](https://github.com/comodojo/wpapi)[ Packagist](https://packagist.org/packages/comodojo/wpapi)[ Docs](https://comodojo.org)[ RSS](/packages/comodojo-wpapi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

comodojo/wpapi
==============

[](#comodojowpapi)

[![Build Status](https://camo.githubusercontent.com/86c6cb2d9f3c0beb08a0c25efb2803435947c64ab5982decaa7da6529087a810/68747470733a2f2f6170692e7472617669732d63692e6f72672f636f6d6f646f6a6f2f77706170692e706e67)](http://travis-ci.org/comodojo/wpapi) [![Latest Stable Version](https://camo.githubusercontent.com/f223ea9e75cba0945172df27f1d51d95533ee9de7e24e7091ab90a370259c379/68747470733a2f2f706f7365722e707567782e6f72672f636f6d6f646f6a6f2f77706170692f762f737461626c65)](https://packagist.org/packages/comodojo/wpapi) [![Total Downloads](https://camo.githubusercontent.com/8e33addb7bb5169e420f7b894911e6144254108e4ab8f9cc60e07a7d55638aab/68747470733a2f2f706f7365722e707567782e6f72672f636f6d6f646f6a6f2f77706170692f646f776e6c6f616473)](https://packagist.org/packages/comodojo/wpapi) [![License](https://camo.githubusercontent.com/37f22cabdc4b44167aaab21ec989ece4f0f53d1547a5cc5a6b6272c06541c4cc/68747470733a2f2f706f7365722e707567782e6f72672f636f6d6f646f6a6f2f77706170692f6c6963656e7365)](https://packagist.org/packages/comodojo/wpapi) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/6093db0829d0a67d1b285c5edf4491c23a167e63a9fae22c9e7233a7f0d8c412/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6d6f646f6a6f2f77706170692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/comodojo/wpapi/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/1a0117dc3c772606d1abb3ceaae847c2fd3837dedaa17642abf4c918db8aeacf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6d6f646f6a6f2f77706170692f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/comodojo/wpapi/?branch=master)

A [XML-RPC Wordpress API](https://codex.wordpress.org/XML-RPC_WordPress_API) wrapper. It uses the [comodojo/rpcclient](https://github.com/comodojo/rpcclient) to send requests.

This lib is intended to be used as a remote Wordpress handler.

Installation
------------

[](#installation)

Install [composer](https://getcomposer.org/), then:

`composer require comodojo/wpapi 1.0.*`

Basic usage
-----------

[](#basic-usage)

Getting recent posts from a blog:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Get last 10 posts (methods are chainable)
	    $posts = $wp->getBlogByID(1)->getLatestPosts();

	    // $posts is an Iterator object, so it can be used in a foreach statement
	    foreach ($posts as $p) {

	    	echo "" . $p->getTitle()   . "";
	    	echo ""  . $p->getContent() . "";

	    }

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Retrieving profile informations:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Get profile
	    $profile = $wp->getBlogByID(1)->getProfile();

	    echo "Hello " . $profile->getDisplayName() . "!";

	    // You can edit your profile informations
	    $profile->setFirstname("Arthur")->setLastname("Dent")->save();

	    echo "Don't forget your towel " .
	    	$profile->getFirstname() . " " . $profile->getLastname() . "!";

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Adding a new post:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Let's create a new post on the main blog
	    $new_post = new \Comodojo\WPAPI\WPPost($wp->getBlogByID(1));

	    // Chain like there's no tomorrow
	    $new_post->setTitle("Awesome new post")
	      ->setContent("This is a really awesome test post")
	      ->addTag("test") // Add a few tags and a category
	      ->addTag("awesomeness")
	      ->addTag("wpapi")
	      ->addCategory("wpapi")
	      ->setStatus("publish") // By default, all posts are saved as "draft"
	      ->save();

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Adding a new page:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Let's create a new page on the main blog
	    $new_page = new \Comodojo\WPAPI\WPPost($wp->getBlogByID(1));

	    // A page is basically a post with a different 'type' value
	    $new_page->setTitle("Awesome new page")
	      ->setContent("This is a really awesome test page")
	      ->setType("page") // Yep, in order to create a page you just need to set the type
	      ->setStatus("publish")
	      ->save(); // Don't forget to save when you've done chaining

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Retrieving comments for a specific post:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Initialize a post object
	    $post = new \Comodojo\WPAPI\WPPost($wp->getBlogByID(1));

	    // You can load a post starting from its ID
	    // and then retrieve its comments
	    $comments = $post->loadFromID(42)->getComments();

	    // Show how many comments are available
	    echo "Total comment(s): ". $comments->getTotal() ."";

	    // $comments is an Iterator object, so it can be used in a foreach statement
	    foreach ($comments as $c) {

	    	echo "" . $c->getAuthor()  . "";
	    	echo ""  . $c->getContent() . "";

	    }

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Fetching the media library:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Initialize a media gallery iterator
	    // You can filter the results by the mime-type
	    $library = $wp->getBlogByID(1)->getMediaLibrary("image/jpeg");

	    /* The iterator is meant to load each object on demand during iteration.
	     * This means that it won't do any query to Wordpress until you start
	     * fetching through the media library. It should save time and resources,
	     * but it won't allow you to know how many objects you have in the library
	     * until you've fetched them all.
	     */
	    foreach ($library as $img) {

	    	echo "";

	    }

	    echo "Total images: " . $library->getFetchedItems() . "";

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Add an image to a post:

```
try {

    // Create a new Wordpress instance
    $wp = new \Comodojo\WPAPI\WP( "www.example.org" );

    // Log in to the server
    if ($wp->login("awesome_user", "awesome_password")) {

	    // Load a post (you can use the 'loadFromID' method or
	    // set the post ID directly into the constructor)
	    $post = new \Comodojo\WPAPI\WPPost($wp->getBlogByID(1), 42);

	    // Create an image
	    $image = new \Comodojo\WPAPI\WPMedia($wp->getBlogByID(1));

	    // You can set the image object as an attachment to the post
	    // This only works BEFORE calling the 'upload' method
	    $image->setPostID($post->getID());

	    // Upload a file directly to Wordpress
	    // if you have a buffer of data, you can use the 'uploadData' method instead
	    $image->upload("/path/to/file.jpg")->save();

	    // You can both add the image as post thumbnail and append it to the content
	    $post->setTitle( $post->getTitle() . " (with image)" )
	    	->setThumbnail($image)
	    	->setContent( $post->getContent() . "" )
	    	->save();

	}

} catch (\Exception $e) {

	/* something went wrong :( */

}
```

Documentation
-------------

[](#documentation)

For a full documentation of the project, check the [Comodojo API](https://api.comodojo.org/libs/Comodojo/WPAPI.html) page.

Contributing
------------

[](#contributing)

Contributions are welcome and will be fully credited. Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

`comodojo/wpapi` is released under the MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Total

3

Last Release

3927d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4cc933c2d1b92f7fd32abb459387bff69fc8a87158b1474171ccf26139904706?d=identicon)[comodojo](/maintainers/comodojo)

---

Top Contributors

[![mcastiello](https://avatars.githubusercontent.com/u/12670283?v=4)](https://github.com/mcastiello "mcastiello (86 commits)")[![marcogiovinazzi](https://avatars.githubusercontent.com/u/12754673?v=4)](https://github.com/marcogiovinazzi "marcogiovinazzi (2 commits)")

---

Tags

apiwordpresswrapperxmlrpc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/comodojo-wpapi/health.svg)

```
[![Health](https://phpackages.com/badges/comodojo-wpapi/health.svg)](https://phpackages.com/packages/comodojo-wpapi)
```

###  Alternatives

[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[hieu-le/wordpress-xmlrpc-client

A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API with full test suite built in

118158.5k2](/packages/hieu-le-wordpress-xmlrpc-client)[wp-graphql/wp-graphql-woocommerce

WooCommerce bindings for WPGraphQL

69146.8k](/packages/wp-graphql-wp-graphql-woocommerce)[php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

16553.3k1](/packages/php-tmdb-laravel)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)[lasserafn/laravel-economic

Economic REST wrapper for Laravel

1118.5k](/packages/lasserafn-laravel-economic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
