WordPress Development

My Favorite WordPress CLI Commands

June 16, 2017

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 bob@example.com --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?

You might also like...

4

Dec.

Modernizing WordPress Development with Sage 9 – Part 3

In Part 1 and Part 2 of this series, we’ve covered Controller in Sage 9. According to MVC pattern (Model-View-Controller), in the ideal circumstance, Views and Controller will be completely separated which enables us to reuse Views more conveniently Imagine you are tailoring a website. There are parts that share the same HTML markup but use … Continued

1

Aug.

Modernizing WordPress Development with Sage 9 – Part 2

In the previous post, we introduced you to Sage 9, our choice when it comes to developing a WordPress theme from scratch. Sage 9 contains a ton of content and features that can help you modernize your WordPress development process. As we mentioned previously, Sage 9 utilizes the already-popular Blade Template Engine from Laravel. One of the … Continued

12

Jul.

Modernizing WordPress Development with Sage 9 – Part 1

At Fresh Consulting, we’ve been using Sage as THE starter theme for some time now. Sage itself has been pushing WordPress development on more modern technologies. And with Sage 9, this has become a big step in WordPress development. Some aspects of the development workflow for WordPress are ancient and obsolete. This is where Sage 9 … Continued