Topic in WP-CLI

Using WP-CLI Command Line Tools

Last Updated -


All VPS and Enterprise plans come with a powerful command line tool known as wp-cli  For an overview of basic commands, open terminal and enter the following. 

$ cd ~/sites/domain-to-manage
$ wp --help 

You should receive the following list.

cache               Manage the object cache.
  cap                 Manage user capabilities.
  cli                 Get information about WP-CLI itself.
  comment             Manage comments.
  core                Download, install, update and otherwise manage WordPress proper.
  db                  Perform basic database operations.
  eval                Execute arbitrary PHP code after loading WordPress.
  eval-file           Load and execute a PHP file after loading WordPress.
  export              Export content to a WXR file.
  help                Get help on a certain command.
  import              Import content from a WXR file.
  media               Manage attachments.
  menu                List, create, assign, and delete menus
  network
  option              Manage options.
  plugin              Manage plugins.
  post                Manage posts.
  rewrite             Manage rewrite rules.
  role                Manage user roles.
  scaffold            Generate code for post types, taxonomies, etc.
  search-replace      Search/replace strings in the database.
  shell               Interactive PHP console.
  sidebar             Manage sidebars.
  site                Perform site-wide operations.
  super-admin         List, add, and remove super admins from a network

Each top-level command has multiple subcommands to use. In order to view all subcommands of a specific command you can use wp <command>  --help  Here is an example for viewing the available subcommands for wp plugin

 wp plugin --help

This will return the following

NAME

  wp plugin

DESCRIPTION

  Manage plugins.

SYNOPSIS

  wp plugin 

SUBCOMMANDS

  activate          Activate a plugin.
  deactivate        Deactivate a plugin.
  delete            Delete plugin files.
  get               Get a plugin.
  install           Install a plugin.
  is-installed      Check if the plugin is installed.
  list              Get a list of plugins.
  path              Get the path to a plugin or to the plugin directory.
  search            Search the wordpress.org plugin repository.
  status            See the status of one or all plugins.
  toggle            Toggle a plugin's activation state.
  uninstall         Uninstall a plugin.
  update            Update one or more plugins.

Some commonly used wp-cli commands.

$ wp plugin status

Displays your current plugins details showing which are active/inactive and if they have an update available

$ wp theme status

Displays a list of installed themes, your active theme and updates available

$ wp db query

Opens Mysql command line client to interact with the database

$ wp search-replace

Database search and replace, also handles serialized arrays

wp search-replace example (note: please be cautious when using search-replace and make sure to always back up your database first) 

$ wp search-replace 'http://old-domain.com' 'http://new-domain.com'

This will update the database replacing http://old-domain.com with http://new-domain.com

The --recurse-objects parameter will handle replacements for widgets and theme options

Nearly all common WordPress functions are available in wp-cli for a full list and updates of new commands that become available you can check the official wp-cli website.

Please view our wp-cli blog post for some extra tips

Related Topics

  • Using WP-CLI Command Line Tools
    All VPS and Enterprise plans come with a powerful command line tool known as wp-cli  For an overview of basic command...

  • WP-CLI Database Commands
    Note: Please use caution when performing commands on the database and always make sure to take a backup first. WP-CL...

  • Multisite Database Commands
    NOTE: These commands are for subfolder multisite only. If you are using multiple domains in your sub sites please con...

Pagely is the Managed WordPress Hosting Platform designed to exceed the needs of media, business, and Enterprise customers alike. We help the world's biggest brands scale WordPress.

Copyright © 2006-2017 Pagely, Inc. All rights reserved.
Pagely® and WordPress® are registered trademarks.

Pagely
Powered by Zendesk