Article

My Favorite WordPress CLI Commands

FavoriteWPCommands

The WordPress Command Line Interface (WP-CLI) is one of my favorite tools for working with WordPress sites. The WP-CLI gives me quick and direct access to many common WordPress management tasks.

While there are many great tutorials on how to install and use WP-CLI I wanted to share a few of the commands I use most often.


Install New Sites

wp core download

Downloads a copy of the latest WordPress to your current working directory. Can also be used to download specific old versions of WordPress if needed.

wp core config

Creates a wp-config.php file. You can’t run a WordPress site (or most of the WP-CLI commands) without one!

wp core install

Creates the database tables needed to run WordPress.


Maintain Existing Sites

wp core version

Prints the current WordPress core version number.

wp core update

Updates WordPress to the latest version.

wp search-replace foo bar

When moving WordPress databases between sites (e.g. staging, testing, development, etc) it’s common for the site URL to change. The WordPress database stores the site URL; in many places those URLs are inside PHP serialized strings. This command searches through your database, finds all instances of one string (e.g. an old URL) and replaces them with the new string (e.g. a new URL) without breaking the PHP serialized strings.

wp user create bob [email protected] --role=administrator

Don’t know the admin login for a site? No problem! Just create a new user.

wp transient --delete

Especially helpful when writing code that reads and writes transients and you need to test from a clean slate.


Work With Plugins

wp plugin list

Prints a handy list of all currently installed plugins along with their version, current activation status, and whether or not a newer version is available.

wp plugin install foo

Install a plugin! Can also be used to install specific versions of a plugin if needed.

wp plugin install foo

Activate a plugin!

wp plugin deactivate foo

Deactivate a plugin!


Work With Databases

wp db export

Quick and easy database exports.

wp db import

Quick and easy database imports.

wp db cli

No need to pull the database password from the wp-config.php file–this command connects to your database and gives you a console so you can run ad-hoc queries.


WP-CLI offers almost 200 different commands. Which do you use most often?

Steve-Hulet-Default-BW_optimize.jpg

Steve Hulet

CTO

Steve is the Co-Founder and CTO at Fresh. A former Software Engineer at Amazon with over 12 years of web development experience, Steve provides technical, architectural, and engineering oversight to projects. Steve is responsible for all technology reviews related to websites. His specialities include programming languages such as C, C++, Java, Python, and PHP, and technology software including Eclipse, GLPK, jQuery, Linux, and MATLAB. Steve’s skills include automation, databases, linear programming, optimization, and testing, all of which he uses in conjunction with Fresh’s digital strategists provide innovative solutions to clients.