Using WP-CLI

Andrew Woods
Andrew Woods
https://andrewwoods.net/blog/2015/using-wp-cli/

The WordPress admin is the primary way to administer your website. It does a lot to empower you as a user. It makes it easy to create and publish your content. Sometimes though, it’s not the right tool for the job. Sometimes, what you need is the command line. Fortunately there is a great command line tool that lets you administer WordPress sites — WP CLI.

Developers know just how powerful of a tool the command line can be. A couple of commands or a small script can remove a lot of needless repetition. Using WP-CLI, you can apply that same power to your WordPress sites. To get started, the, follow the install instructions on the WP-CLI homepage. If you don’t know the root password, the sudo mv command won’t work. If that is your situation, These steps will fix it:

$ mkdir ~/bin
$ mv wp-cli.phar ~/bin/wp
$ vim ~/.bash_profile  # edit your .bash_profile

In your .bash_profile, add the following line to the bottom

export PATH=$PATH:$HOME/bin

Now just open a new terminal window. You can see it work:

$ wp --info

Now that it’s working. There are a lot of great commands that make it easy to work with WordPress. Here are several:

Download the latest version of WordPress

$ wp core download

Look up your current WordPress version

$ wp core version

List your 5 most recent posts

$ wp post list --post_type=post --fields=ID,post_title,post_name,post_date --post_status=publish --posts_per_page=5

Update all your plugins

$ wp plugin update --all

Find all the unapproved comments

$ wp comment list --fields=comment_ID,comment_post_ID,comment_date,comment_approved --status=hold

To view a single comment

$ wp comment get <id>

To approve a comment

$ wp comment approve <id>

Sorry, but comments are closed. I hope you enjoyed the article