How to Use WordPress CLI to Streamline Development

If you’ve been managing a WordPress site for a while, you know how tedious it can be to navigate the admin panel just to update plugins, manage users, or clear cache.

When himessentials.com and this site, marai.dev, were just starting, they were initially hosted on my DIY home server because I was trying to minimize operational costs. However, handling frequent updates and debugging production issues through the WordPress dashboard started to feel inefficient.

That’s where WP-CLI (WordPress Command Line Interface) comes in. WP-CLI lets you interact with WordPress from the command line, making development, maintenance, and troubleshooting significantly faster. If your WordPress site runs on a VPS, Docker container, or local development setup, learning WP-CLI will save you a ton of time.

In this post, I’ll walk you through setting up WP-CLI, performing common tasks, and automating repetitive actions. This blog post isn’t for everyone, especially if you’re using a WordPress hosting provider, as some providers already have maintenance services built into their packages. If you have the budget, I recommend going that route. However, if you’re like me back then, trying to minimize operational costs by using a home server, this blog post might be helpful for you.


Setting Up WP-CLI

Before we start using WP-CLI, we need to install it. If you’re running WordPress on a Linux-based server (which I highly recommend for performance reasons), you can install WP-CLI with:

Bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp

To check if it’s installed correctly, run:

Bash
wp --info

If you’re using Docker, you don’t need to install WP-CLI separately—just access your WordPress container and use wp directly. If you’ve set up WordPress inside a Docker container, you can run:

Bash
docker exec -it my-wordpress-container wp --info

Now that WP-CLI is set up, let’s dive into some real-world use cases.


Common WP-CLI Commands

Here are some WP-CLI commands that I frequently use when managing himessentials.com:

1. Updating WordPress Core, Themes, and Plugins

Updating WordPress manually through the admin panel takes time. With WP-CLI, you can do everything in seconds:

Bash
wp core update
wp plugin update --all
wp theme update --all

This is especially useful when performing scheduled maintenance on production sites, ensuring all components are up to date.

2. Managing Users

Instead of creating users manually in the WordPress admin, you can add an admin user with:

Bash
wp user create newadmin newadmin@example.com --role=administrator --user_pass=SecurePass123

You can also reset a user’s password (a lifesaver when clients forget their login):

Bash
wp user update newadmin --user_pass=NewSecurePass456
3. Creating and Managing Posts

If you’re bulk-importing blog content, you can create a post instantly:

Bash
wp post create --post_title="How to Choose the Best Men's Skincare Products" --post_content="This is an auto-generated post about skincare." --post_status=publish --post_author=1

Want to delete all draft posts? Run:

Bash
wp post delete $(wp post list --post_status=draft --format=ids)
4. Database Operations

WP-CLI can optimize your database, reducing query times and improving performance:

Bash
wp db optimize

You can also export and import the database without using phpMyAdmin:

Bash
wp db export backup.sql
wp db import backup.sql

If you’re working with multiple environments (local, staging, production), this is super useful for migrating databases.

5. Clearing Cache (for Caching Plugins)

If you’re using WP Super Cache or W3 Total Cache, you can clear the cache instantly:

Bash
wp cache flush

No need to log into the admin panel just to click that “Clear Cache” button.


Automating WP-CLI Tasks

One of the best things about WP-CLI is that you can automate these tasks with cron jobs or shell scripts.

For example, let’s say you want to auto-update plugins daily. Just add this to your crontab (crontab -e):

Bash
0 2 * * * /usr/local/bin/wp plugin update --all --allow-root

This runs wp plugin update –all every night at 2 AM. No more worrying about outdated plugins!


WP-CLI is a game-changer for WordPress developers. Whether you’re managing a blog or running an eCommerce store like himessentials.com, using WP-CLI will speed up your workflow, automate tedious tasks, and give you more control over your site.

If you’re new to WP-CLI, start with simple tasks like updating plugins and clearing cache. Once you’re comfortable, move on to database management and automation, that’s where WP-CLI truly shines.

Assi Arai
Assi Arai
Articles: 37