WP-CLI is the WordPress Command Line Interface. It’s a way of interacting with WordPress from the command line and is especially useful in scripting.


Common Tasks/How-To’s

Create a Site

  wp core download
  wp config create --dbhost=host.db --dbname=dbname --dbuser=username --dbpass=password
  wp core install --url=yourwebsite.com --title="" --admin_name= --admin_password= --admin_email=

Delete all content

wp post delete $(wp post list --post_type='bulletin' --format=ids)
wp post delete $(wp post list --post_type='post' --format=ids)

Export configuration

Note: jq (jq website) is a command line JSON processor that – among many things – will take a JSON string and produce formatted JSON output (i.e., pretty-printed). Using formatted output makes the json files easier to diff for changes. jq isn’t required if this isn’t an issue.

wp option get theme_mods_craft-blog --format=json | jq > theme_mods_craft-blog.json

wp option get powerpress_feed         --format=json | jq > powerpress_feed.json
wp option get powerpress_feed_podcast --format=json | jq > powerpress_feed_podcast.json
wp option get powerpress_general      --format=json | jq > powerpress_general.json

Get Login URL from command line

wp eval 'echo wp_login_url() . "\n";'