Skip to content

Instantly share code, notes, and snippets.

@sborka-ua
Created October 12, 2018 18:52
Show Gist options
  • Save sborka-ua/9efaa604d47b20252dc324ab3d15c35d to your computer and use it in GitHub Desktop.
Save sborka-ua/9efaa604d47b20252dc324ab3d15c35d to your computer and use it in GitHub Desktop.
WP CLI commands
////// WP CLI commands ////////
cd wordpress/
// Import DB backup from SQL file
wp db import ../dump.sql
// Export DB backup to SQL file
wp db export
tar -zcvf [name]_[yyyy-mm-dd].tar.gz ../
// WP core version
wp core version --extra
// Update WordPress
wp core update
wp core update-db
wp plugin update --all
wp theme update --all
// Delete expired transients.
wp transient delete --expired
// Search/replace to a SQL file without transforming the database.
// Use carefull! If file exists, it will be replaced by new dump
wp search-replace utf8mb4_unicode_520_ci utf8mb4_unicode_ci --export=../dump.sql
// Show search/replace in DB report, but don’t save changes to the DB
wp search-replace 'old_value' 'new_value' --dry-run
// or
wp search-replace 'old_value' 'new_value' wp_posts wp_postmeta wp_terms wp_options --dry-run
// Search in DB for 'utf8mb4_unicode_520_ci'
wp db search 'search_value'
// List themes
wp theme list
// List plugins
wp plugin list
// List sidebars
wp sidebar list
// List widgets on a given sidebar
wp widget list <sidebar-id>
// List existing menus
wp menu list
// List posts (ID | post_title | post_name | post_date | post_status)
wp post list
// Get details about a post
wp post get 123
// Get content of the post with ID=1
wp post get 1 --field=content
// List post types
wp post-type list
// List post types with 'post' capability type
wp post-type list --capability_type=post --fields=name,public
// WP option get blogdescription
wp option get blogdescription
// WP option get site URL
wp option get siteurl
// WP option update site URL
wp option update siteurl '{"foo": "bar"}' --format=json
// Update admin email address.
wp option update admin_email someone@example.com
// List constants and variables defined in wp-config.php file
wp config list
// Get the table_prefix as defined in wp-config.php file
wp config get table_prefix
// List only database user and password from wp-config.php file
wp config list DB_USER DB_PASSWORD --strict
// List only database name from wp-config.php file
wp config list DB_NAME
// Find WP installations in the OS
wp find ./
// (if wp find command is not found, install the package: wp package install wp-cli/find-command )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment