Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Use WP-CLI for Command-Line Site Management

- 30.03.26 - ErcanOPAK

⚑ Manage WordPress from Terminal

Clicking through admin for every site update? Slow. WP-CLI lets you install plugins, update core, manage usersβ€”all from command line. 10x faster.

Install WP-CLI

# Download
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# Make executable
chmod +x wp-cli.phar

# Move to PATH
sudo mv wp-cli.phar /usr/local/bin/wp

# Test
wp --info

πŸš€ Essential Commands

# Update WordPress core
wp core update

# Install plugin
wp plugin install contact-form-7 --activate

# Update all plugins
wp plugin update --all

# Install theme
wp theme install twentytwentyfour --activate

# Create user
wp user create john john@example.com --role=editor

# Search & replace in database
wp search-replace 'http://oldsite.com' 'https://newsite.com'

# Export database
wp db export backup.sql

# Import database
wp db import backup.sql

# Clear cache
wp cache flush

# Generate posts for testing
wp post generate --count=100

Real-World: Bulk Site Management

πŸ“¦ Update 50 Sites Script

#!/bin/bash

sites=(
  "/var/www/site1"
  "/var/www/site2"
  "/var/www/site3"
  # ... 47 more
)

for site in "${sites[@]}"; do
  echo "Updating $site"
  cd "$site"
  
  # Backup first
  wp db export "backup-$(date +%Y%m%d).sql"
  
  # Update everything
  wp core update
  wp plugin update --all
  wp theme update --all
  
  echo "βœ“ $site updated"
done

# 50 sites updated in 10 minutes instead of 5 hours

Migration Made Easy

# On old server
wp db export oldsite.sql
wp media regenerate --yes  # Regenerate thumbnails

# Transfer files + database to new server
scp -r wp-content/ user@newserver:/var/www/html/
scp oldsite.sql user@newserver:/tmp/

# On new server
wp db import /tmp/oldsite.sql
wp search-replace 'http://oldsite.com' 'https://newsite.com'
wp search-replace '/old/path' '/new/path'
wp cache flush

# Done! Site migrated

βœ… Power User Commands

  • wp post list: List all posts with filters
  • wp media regenerate: Regenerate all image sizes
  • wp user list: Show all users with roles
  • wp option get siteurl: Get any option value
  • wp plugin list –status=inactive: Find unused plugins
  • wp transient delete –all: Clear all transients

πŸ’‘ Cheat Sheet

Task Command
Update core wp core update
Install plugin wp plugin install [name] --activate
Backup DB wp db export backup.sql
Search/Replace wp search-replace 'old' 'new'
Clear cache wp cache flush

“Manage 30 client sites. Before WP-CLI: 2 hours to update everything. After: Created bash script with WP-CLI. 10 minutes, all sites updated, backed up, tested. Game changer.”

β€” WordPress Agency Owner

Related posts:

WordPress Query Monitor: Debug Performance Issues in Real Time

The Silent SEO Killer: Auto-Generated Attachment Pages

WordPress β€” REST API Enabled = Attack Surface

Post Views: 2

Post navigation

Photoshop: Convert to Smart Objects for Non-Destructive Editing
WordPress: Use REST API to Build Headless WordPress Applications

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (751)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (751)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com