WordPress Command Line Interface = wp-cli
You can use command-line tool with any of your servers. They usually comes with your server setup. All you need to do is add/activate SSH users for your server and then you can run WordPress commands using your terminal app. You can make changes to database and plugins just using the terminal, without even going to the server dashboard.
Basic wp-cli commands
This will show all wp-cli commands list.
wp
Get help for a specific command
wp plugin --help
wp cli version
wp cli check-update
wp cli update
wp-cli commands for plugins
wp plugin list
wp plugin install plugin-name
wp plugin activate plugin-name
wp plugin deactivate plugin-name
Activate or Deactivate (toggle plugin status) a plugin
wp plugin toggle plugin-name
wp-cli commands for themes
wp theme list
wp theme install theme-name
wp theme activate theme-name
wp theme update theme-name
wp-cli commands for WordPress
Check the current core WordPress version
wp core version
Check if core WordPress updates are available
wp core check-update
wp core update
Force download and overwrite core WordPress files
wp core download --force
wp-cli commands for WordPress users
wp user list
This will create a new user with an email address and a role. A temporary password will be printed in return of the command.
wp user create enter-username [email protected] --role=administrator
Change a password using user ID number
If you’re not sure about the user ID number then you can get the users list.
wp user update 11 --user_pass=enter new password
In the example above, 11 is the user ID number.
Deleting user requires a user ID as well.
If you’re not sure about the user ID number then you can get the users list.
When you delete a user, you need to reassign that user’s posts to another user so those posts are not permanently deleted.
wp user delete 10 --reassign=1
wp-cli commands for cache management
wp cache flush
wp cli cache clear
wp rewrite flush
wp-cli commands for database management
wp db check
wp db optimize
wp db repair
Search the database for a specific string
wp db search yogesh
Update the database to the latest version available
wp core update-db
Search and replace a string in the database
wp search-replace https://yogeshchauhan.com https://yogeshchauhan.com/blog
Make sure you run the search and replace command above with a –dry-run flag. It will show you what will change and in which tables.
Search and replace with a –dry-run flag
wp search-replace https://yogeshchauhan.com https://yogeshchauhan.com/blog --dry-run
wp-cli commands for home and siteurl
wp option list | grep -E "^(siteurl|home)"
wp option update home https://yogeshchauhan.com
wp option update siteurl https://yogeshchauhan.com
wp-cli commands for wp-config.php file
View all settings in wp-config.php file
wp config list
Update a setting in wp-config.php file
wp config set DB_NAME local
wp config set DB_USER root
command-line list search SSH wp-cli