Michele Cheow

Turning caffeinated beverages into code since '07

Mamp logo and WP-CLI logo

WP-CLI: Not all dev tools wear capes

November 28, 2023 by mcheow Leave a Comment

If you’re a #WordPress developer, you’ve probably heard of WP-CLI, the command-line interface for WordPress. But what exactly is it? And why should you care? And did you know you can also use it locally?

WP-CLI is a tool that allows you to manage your WordPress sites from the command line. This means you can perform tasks like creating and updating posts, managing plugins and themes, and even backing up your site, all without having to log in to your dashboard.

So, why should you use WP-CLI?

It’s faster. It’s often faster than using the WordPress dashboard, especially for tasks that you repeat often.

It’s more powerful. It can do things that you can’t do with the dashboard, like managing your site’s .htaccess file or running scripts.

It’s more flexible. It can be used to automate tasks and integrate with other tools, making it a powerful tool for developers.

I recently started freelancing on a WordPress project and decided to try it out. Since I prefer to run WordPress locally on my machine and because my Mac is still kicking at 10+ years old, I went old school and used #MAMP. (Docker doesn’t work on older machines 😫).

I wanted to try running a search and replace on the imported database locally to find all instances of the staging url and replace it with my localhost url. Normally, I would use Migrate DB Pro, which handles this automatically but wanted to try a different method. WordPress plugins? Don’t know her. 😁

After installing, I navigated to the root level of my WP install, the same level as my wp-config file. I ran “wp option get siteurl” to test the correct url was getting returned and I got an error.

After reading through the WP-CLI docs, #StackOverflow, and general Googling, I found out that in your wp-config file, you need to add the port number to your database hostname.

Once that was done, I ran “wp search-replace ‘staging-url’ ‘localhost url'” and it worked like a charm. If you want, you can even target the search and replace to specific tables.

There are a ton of commands available, so it’s recommended to learn the basics before you can use it effectively.

There are a few great resources available for learning WP-CLI:

The official WP-CLI documentation: https://make.wordpress.org/cli/

The WP-CLI Cookbook: https://github.com/wp-cli/wp-cli

The WP-CLI Community: https://wordpress.slack.com/messages/C02RP4T41

WP-CLI is a powerful tool that can make life much easier. If you’re not already using it, I highly recommend that you give it a try!

Filed Under: Blog

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About MC

In west Brooklyn born and raised, behind a computer is where I spent most of my days. Codin' out all cool outside of the school.... ok I'm clearly not Will Smith.

In 2007, I got my start in web development, kept it going after college and I landed my first job at Marvel. Several years later, New York City and I developed a rocky relationship and we decided to call it quits. I set my eye on the west coast and landed in Vegas where I dug in deep with the tech scene; attending meetups and planned a few Startup Weekends.

A few years later, I bought a house, got married and planted some roots. Moving was the best decision I've ever made.

Resume

  • Download my resume in PDF format

Connect

  • twitter
  • linkedin
  • codepen
  • github
  • wordpress
  • stackoverflow
  • mail

© 2025 · Michele Cheow