Helpful WP-CLI Commands

WP-CLI is a great tool and we use it every day ourselves for managing WordPress. In this article, we have listed helpful commands we use regularly. To begin using WP-CLI commands you need to be logged in to your site using SSH. To use SSH you need an SSH Terminal. On Mac, there is a program called Terminal. On Windows many users use PuTTY.

Connect to your site with SSH

ssh USERNAME@SERVERNAME 

#Example: 
ssh [email protected]

You will be prompted for your password and can log in.

WP-CLI manual and help commands

Display the WP-CLI manual
There are a lot of WP-CLI commands. Writing this command gives you the full WP-CLI manual. Additionally it also outlines global parameters.

wp

Get more information on a specific command
WP-CLI manual can be much to grasp and not very specific. Writing help before your command gives you more specific information about the command.

wp help <command>

Install WordPress and check the core

Install WordPress – Navigate to ~/public/ folder and run the command

wp core download

Check the WordPress core version installed

wp core version

Update WordPress core to the latest version

wp core update

Plugins

Check WordPress plugins installed
Display every plugin installed in a list. Additionally lists plugin status, update, and version.

wp plugin list

To get the status of all plugins

wp plugin status

Install our Servebolt-Optimizer plugin and activate

wp plugin install servebolt-optimizer --activate

Database

Export your database

wp db export

Import your database

wp db import <name.sql>

Edit config file

wp config edit

Replace all URLs in the database

wp search-replace [old url] [new url] --all-tables

Check website home and site URL

wp option get home
wp option get siteurl

Create admin user

wp user create [username] [e-mail] --role=administrator

Delete admin user

wp user delete <username>

List all users:

wp user list

Debugging and tools

Diagnose your WordPress site using WP Profile and WP Doctor

wp profile stage
wp doctor check --all

Put your site in maintenance mode

wp maintenance-mode activate

Deactivate maintenance mode

wp maintenance-mode deactivate

Flushes the WordPress object cache

wp cache flush

Run all cron jobs

wp cron event run --all

For more WP-CLI commands, check out the official WordPress documentation.

WP-CLI for Servebolt Optimizer

Our plugin ‘Servebolt Optimizer’ also allows the use of CLI. Read more on How to use Servebolt Optimizer for WordPress.