Managing WordPress with WP-CLI

Watch out! This tutorial is over 3 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
Tutorial Difficulty Level    

WP-CLI is a command line interface which allows the users to manage their WordPress web sites from the command prompt. Upgrades can be performed, backups can be generated, new posts can be published and most of the regular admin actions can be performed with a set of commands.

This tutorial explains how to use the WP command line interface in order to complete regular administrative tasks like upgrades, database backup creation, plugins and themes installations and removals, publishing and deleting posts, changing site’s URL settings and getting help on chosen commands.  Once complete, you should be able to combine WP-CLI with Bash, Perl or any other scripting language to create powerful web applications.

Note that the template WordPress Server (with WP-CLI) found in Xen Orchestra (obviously) comes with WP-CLI already installed. Fire up an instance for use when following the below.

List the Available WP-CLI Commands

To list all the commands write “wp help” or just “wp”. The following list will be shown:

If you want to get detailed documentation, for example for the “wp db export” command, enter the command listed below:

The result will be as follows:

Update WordPress via WP-CLI

First, you need to check the current version of WordPress that you have:

f you would like to upgrade your WordPress core to a newer version, you can do that via the following command:

Update WordPress Plugins using WP-CLI

If you would like to upgrade any additional plugins or themes on your WordPress website, you could do that with WP-CLI. To check for example the status of the currently installed plugins, use this command:

We have 5 plugins integrated in our sample installation. There is an upgrade for one of them. To perform an upgrade for that plugin, the following command can be used:

Install and Activate WordPress Plugins & Themes via WP-CLI

To install and activate a new plugin, execute the commands listed below:

You should replace the “Plugin_Name” string with the exact plugin name.

Other Tasks you Can do With WP-CLI

You can write posts directly from the command line. To create a post, use the following command:

If you do not need a certain post you can easily delete it:

Example Use Case

This example script could automatically download, configure, and install WordPress core, remove starting plugins, add and activate a specified theme (saved in, then install and activate a list of plugins you’d prefer to use with new installations.

Actually, something quite like this is used by Computer Services to create new WordPress installs for students on the department server.

More details on WP-CLI can be found through the help command and the project’s home page.