Essential WP-CLI Commands for Hosting Support
WP-CLI is an indispensable tool for managing WordPress installations via the command line. It is significantly faster for bulk operations and is essential for troubleshooting issues when the WordPress dashboard is inaccessible.
1. Site URL and Database Management
Section titled “1. Site URL and Database Management”When migrating a site or changing domains, the first step is updating the core options in the wp_options table.
Check Current URLs
Section titled “Check Current URLs”wp option get siteurlwp option get homeUpdate Site URLs
Section titled “Update Site URLs”wp option update home '[https://newurl.tld](https://newurl.tld)'wp option update siteurl '[https://newurl.tld](https://newurl.tld)'2. Global Search and Replace
Section titled “2. Global Search and Replace”After updating the URL options, you must run a search and replace on the entire database to fix serialized links in your posts and metadata.
Dry Run (Preview Changes)
Section titled “Dry Run (Preview Changes)”Always perform a dry run first to see how many replacements will be made. Use | tail -1 to see a clean summary.
wp search-replace '[https://oldurl.tld](https://oldurl.tld)' '[https://newurl.tld](https://newurl.tld)' --skip-columns=guid --dry-run | tail -1Execute Replacement
Section titled “Execute Replacement”wp search-replace '[https://oldurl.tld](https://oldurl.tld)' '[https://newurl.tld](https://newurl.tld)' --skip-columns=guid | tail -13. Bulk Updates and Maintenance
Section titled “3. Bulk Updates and Maintenance”Use these commands to force-update components or repair a site that has corrupted files or plugin conflicts.
Force Updates
Section titled “Force Updates”wp plugin update --all --forcewp theme update --all --forceBulk Reinstall (Repair)
Section titled “Bulk Reinstall (Repair)”This command fetches a fresh copy of every currently installed plugin or theme from the WordPress repository.
# Reinstall all pluginswp plugin install $(wp plugin list --field=name) --force
# Reinstall all themeswp theme install $(wp theme list --field=name) --force4. WP-Cron and Background Tasks
Section titled “4. WP-Cron and Background Tasks”If scheduled events (like backups or publishing) are failing, check the cron event queue.
List Scheduled Events
Section titled “List Scheduled Events”Using --skip-plugins ensures that a broken plugin doesn’t prevent the command from running.
wp cron event list --skip-pluginsExecute Due Tasks
Section titled “Execute Due Tasks”Manually trigger all events that are currently due to run:
wp cron event run --due-now5. Core Integrity and Security
Section titled “5. Core Integrity and Security”Use these commands to verify that the core WordPress files have not been modified or corrupted.
Verify Checksums
Section titled “Verify Checksums”wp core verify-checksumsForce Core Reinstall
Section titled “Force Core Reinstall”If checksums fail, you can reinstall WordPress core files without affecting your content or database:
wp core download --version=$(wp core version) --force