Home / WordPress / 30 Useful WP-CLI Commands Every Developer Should Know
devmohsin143

If you want to speed up your development workflow, mastering WP-CLI commands is the ultimate game-changer. Logging into the WordPress admin dashboard, navigating through multiple menus, and clicking through options is fine for casual bloggers, but as a professional developer, your time is valuable. By executing tasks directly from your command-line interface, you can accomplish in seconds what used to take minutes, paving the way for seamless WordPress automation.

In this guide, we have compiled a comprehensive list of 30 essential WP-CLI commands that every WordPress developer should have in their toolkit. From automated installations to database optimization, plugin management, and server administration, these commands will transform your terminal into a powerful administration panel.

What is WP-CLI and Why Use It?

WP-CLI is the official command-line interface for WordPress. It allows you to manage almost every aspect of a WordPress site without opening a web browser. With WP-CLI, you can update plugins, configure multisite installations, perform database migrations, and bulk-generate content via command-line arguments. Additionally, because WP-CLI bypasses the web browser, it avoids timeout limits on heavy operations, making it incredibly fast and reliable.

To use these commands, you must have SSH access to your web server and have the WP-CLI tool installed. For detailed installation steps, check out our comprehensive WP-CLI Beginner’s Guide.

Essential WP-CLI Commands for Core Installation and Updates

Setting up a fresh WordPress environment can be tedious. Use these core commands to install, update, and manage the base WordPress application instantly.

1. wp core download

This command downloads the latest version of WordPress directly into your current directory. It automatically pulls files from the official WordPress repository.

wp core download

You can also download a specific version or language by appending flags:

wp core download --version=6.4.2 --locale=en_GB

2. wp core config

Generate your wp-config.php file securely without manually copying and pasting database credentials.

wp core config --dbname=my_db_name --dbuser=db_user --dbpass=secure_password --dbhost=localhost

3. wp core install

Run the famous WordPress five-minute installation in less than five seconds.

wp core install --url=https://yourdomain.com --title=\"My WP-CLI Site\" --admin_user=admin_username --admin_password=strong_password_here --admin_email=info@yourdomain.com

4. wp core update

Keep your WordPress core up to date without visiting the dashboard. It checks for updates and installs them automatically.

wp core update

5. wp core update-db

After a core update, the WordPress database schema may need updating. Execute this command to perform the database upgrade instantly.

wp core update-db

6. wp core version

Quickly verify the exact version of WordPress currently running on your server.

wp core version

Speed up Database Tasks with WP-CLI Commands

Managing databases is a critical aspect of development. These commands allow you to back up, restore, search, and optimize your database effortlessly.

7. wp db export

Generate a SQL backup file of your WordPress database in a split second. This is an essential step before running risky operations or during migrations.

wp db export my_backup_file.sql

8. wp db import

Import a SQL backup file straight into your database with no maximum upload limit constraints.

wp db import my_backup_file.sql

9. wp db search-replace

This is arguably one of the most powerful WP-CLI commands. It allows you to safely search and replace strings (like changing domains) throughout your database without breaking PHP serialized data.

wp db search-replace 'https://staging.example.com' 'https://example.com' --dry-run

Tip: Always use the --dry-run flag first to preview your changes before altering the database.

10. wp db query

Execute custom SQL queries directly from your terminal. This saves you from having to log in to phpMyAdmin or connect via an external client.

wp db query \"SELECT count(*) FROM wp_posts;\"

11. wp db optimize

Optimize your database tables to clean up overhead and improve site performance.

wp db optimize

12. wp db reset

Need to start from scratch? This command drops all tables in the database. Be extremely careful when using this!

wp db reset --yes

Plugin and Theme Management Using WP-CLI Commands

With these automated WP-CLI commands, you no longer need to manually log in to search, upload, and activate plugins or themes.

13. wp plugin list

View a formatted table of all installed plugins, along with their status (active/inactive), version, and whether updates are available.

wp plugin list

14. wp plugin install

Install any plugin from the WordPress.org directory. You can also install multiple plugins simultaneously.

wp plugin install contact-form-7 woocommerce --activate

To install a plugin from a local zip file or a remote URL, pass the path directly:

wp plugin install https://downloads.wordpress.org/plugin/akismet.zip --activate

15. wp plugin activate

Activate an installed plugin instantly. This is extremely useful if a plugin conflict locks you out of your WP-Admin.

wp plugin activate wp-super-cache

16. wp plugin deactivate

Deactivate one or more plugins without touching the dashboard. Perfect for troubleshooting security issues.

wp plugin deactivate --all

17. wp plugin update

Update all your plugins, or target a specific one, to keep your site secure.

wp plugin update --all

18. wp theme list

Display all installed themes, noting which one is currently active.

wp theme list

19. wp theme install

Download and install a theme. You can active it immediately with the --activate flag.

wp theme install twentytwentyfour --activate

20. wp theme update

Update your themes via CLI in seconds.

wp theme update --all

User Administration Commands

If you lose your WordPress password or need to generate test accounts, these commands are incredibly helpful.

21. wp user create

Create a new user account instantly. You can assign any role, including Administrator.

wp user create developer_jane jane@example.com --role=administrator --user_pass=jane_secure_password

22. wp user list

Get a clean overview of all registered users on your website, organized by role.

wp user list

23. wp user update

Update user details, such as changing a password or editing meta fields.

wp user update developer_jane --user_pass=new_ultra_secure_pass

24. wp user delete

Delete a user. You can reassign their authored posts to another user ID using the --reassign flag.

wp user delete developer_jane --reassign=1

Content and Media Automation

Scale your development by automating content generation, importing bulk media assets, and rebuilding assets.

25. wp post create

Quickly draft or publish articles without leaving your code editor.

wp post create --post_type=page --post_title=\"Privacy Policy\" --post_status=publish

26. wp post generate

Need dummy data for testing theme layouts or performance benchmarking? Generate hundreds of placeholder posts instantly.

wp post generate --count=50

27. wp media import

Import local files into the WordPress Media Library and attach them to posts automatically.

wp media import /path/to/local/image.jpg --post_id=45

28. wp media regenerate

If you change your theme’s image sizes, use this command to regenerate all thumbnails without having to install bulky plugins.

wp media regenerate --yes

Maintenance, Performance, and Cache Management

Fine-tune your server’s performance, clear out junk files, and refresh system caches using these advanced commands.

29. wp transient delete

Transients are used to temporarily store cached data in your database. Clearing expired or broken transients can resolve unexpected UI glitches.

wp transient delete --expired

To delete all transients completely:

wp transient delete --all

30. wp cache flush

Flush your object cache completely. This is incredibly helpful when working with Redis or Memcached servers where updates aren’t showing up instantly.

wp cache flush

WP-CLI vs WP-Admin: Efficiency Comparison

Below is a direct comparison highlighting why developers rely on WP-CLI commands over the graphical user interface for everyday tasks.

ActionWP-Admin GUI ProcessWP-CLI CLI ProcessTime Saved
Install & Activate PluginNavigate to Plugins -> Add New -> Search -> Install -> Activatewp plugin install name --activate~80% faster
Database Backup (Export)Install backup plugin -> Configure settings -> Click Export -> Download filewp db export~95% faster
Update Core, Plugins, ThemesNavigate to Updates -> Check boxes -> Click Update on multiple screenswp core update && wp plugin update --all && wp theme update --all~90% faster
Reset User PasswordGo to Users -> Profile -> Generate Password -> Copy/Paste -> Save Profilewp user update username --user_pass="pass"~75% faster

Best Practices for WordPress Automation with WP-CLI

To implement WordPress automation safely and professionally, you should always follow developer best practices:

  • Always backup first: Before running updates or search-replace scripts, use wp db export.
  • Write shell scripts: Combine your favorite WP-CLI commands into a bash file (e.g., deploy.sh) to provision new staging sites instantly.
  • Use aliases: Configure WP-CLI aliases so you can control remote production sites securely from your local terminal using SSH tunnels.
  • Integrate with CI/CD: Add CLI commands into your GitHub Actions or GitLab pipelines to run automatic database updates upon code deployment.

Conclusion

Mastering WP-CLI is one of the most rewarding milestones for a WordPress developer. By integrating these 30 useful commands into your workflow, you unlock unparalleled speed, efficiency, and the unlimited potential of WordPress automation. Stop clicking, start typing, and take total control over your development environment today!

“The CLI is not about doing things differently; it is about doing things faster, consistently, and without limitations.” – WP Educated Development Team

For more technical tips and tutorials on speed optimization and server management, explore our deep dive into [Internal Link: WordPress Hosting Optimization Guide].

Related Blogs

Learn how to improve WordPress website speed safely. Actionable guide covering image optimization, caching, database cleanup, and hosting without breaking your site.
Confused by speed test scores? Learn how to accurately interpret website speed test results, analyze Core Web Vitals like LCP, INP, CLS, and TTFB, and fix bottlenecks efficiently.
Master the exact workflow for testing WordPress website speed. Learn how to use PageSpeed Insights, GTmetrix, and Core Web Vitals to accurately diagnose performance bottlenecks.