Get started with 33% off your first certification using code: 33OFFNEW

A beginners guide to WP-CLI

2 min read
Published on 1st December 2023

WordPress Command Line Interface (WP-CLI) is a powerful tool that allows you to manage WordPress installations without using a web browser. From updating plugins to managing users and configuring multisite installs, WP-CLI can significantly speed up your WordPress workflow. Let's explore the basics of this indispensable tool.

Understanding WP-CLI

WP-CLI is a set of command-line tools for managing WordPress installations. It enables you to update WordPress, manage plugins and themes, import and export data, run database operations, and much more, all through the command line.

Installing WP-CLI

Before diving into WP-CLI, you need to ensure it's installed on your server. The installation process is straightforward:

  1. Download the WP-CLI .phar file:

    curl -O
  2. Make it executable:

    chmod +x wp-cli.phar
  3. Move it to a directory included in your system's PATH:

    sudo mv wp-cli.phar /usr/local/bin/wp
  4. Test to see if it works:

    wp --info

Using WP-CLI

Once installed, you can start using WP-CLI commands. Here’s a look at some basic but powerful commands:

1. Updating WordPress

To update WordPress to the latest version, use:

wp core update

2. Managing Plugins

  • Install a plugin:

    wp plugin install [plugin-name] --activate
  • Update all plugins:

    wp plugin update --all
  • Deactivate a plugin:

    wp plugin deactivate [plugin-name]

3. Managing Themes

  • Install a theme:

    wp theme install [theme-name]
  • Activate a theme:

    wp theme activate [theme-name]

4. Managing Users

  • Create a new user:

    wp user create [username] [email] --role=[role]
  • Update a user's details:

    wp user update [username] --[field]=[value]

5. Database Operations

  • Optimize the database:

    wp db optimize
  • Repair the database:

    wp db repair
  • Export the database:

    wp db export

6. Working with Posts

  • Create a new post:

    wp post create --post_type=post --post_title='A sample post'
  • Update a post:

    wp post update [post-id] --post_status=publish

WP-CLI Packages

WP-CLI can be extended with additional commands through packages. You can find a list of community packages on the WP-CLI package index.

Best Practices

  • Backup First: Always backup your WordPress site before running WP-CLI commands that modify the database.

  • Stay Updated: Keep your WP-CLI tool updated to access the latest features and security fixes.

  • Explore and Experiment: The best way to learn WP-CLI is by using it. Start with basic commands and gradually explore more complex ones.

WP-CLI is a powerful tool that can greatly enhance your productivity when managing WordPress sites. By familiarizing yourself with its basic commands, you can perform complex tasks quickly and efficiently. Whether you're a developer, site administrator, or a casual WordPress user, WP-CLI is a skill worth acquiring.