WP-CLI Tutorial

Tutorial on How to Use WP-CLI

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. Note that WP-CLI requires a SSH access.

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:

If 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:

You can also create a backup of the WordPress database via WP-CLI, by using the following command:

If you decide to change the primary domain for the WordPress web site you can easily update the corresponding URL options:

More details on WP cli can be found through the help command and the project's home page.