Skip to content

I often reference this list of useful WordPress CLI commands to enhance or clean up my sites.

License

Notifications You must be signed in to change notification settings

MrGKanev/awesome-wordpress-cli-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Awesome WordPress Cli Commands

I often reference this list of useful WordPress CLI commands to enhance or clean up my sites. Please be careful and make backups.

How to install WordPress CLI. Here you can checkout the commands.

List:

Syncing High-Performance Order Storage

wp wc cot sync

Recovering WordPress after a fatal error from plugin update

wp plugin deactivate plugin-says-no --skip-plugins

Cleaning Woocommerce trash products

wp post delete $(wp post list --post_type=product --post_status=trash --format=ids) --force

Cleaning unattached jpegs from the WordPress library

for id in $(wp db query "SELECT ID FROM wp_posts where post_type='attachment' AND post_parent=0 AND post_mime_type='image/jpeg'" --silent --skip-column-names)
do
    wp post delete --force $id
done

Cleaning unattached jpegs from the WordPress library in batches. You can change the batch size by changing the value of the batch_size variable.

# !/bin/bash

# Fetch all IDs in one command and store them in an array

ids=($(wp db query "SELECT ID FROM wp90_posts WHERE post_type='attachment' AND post_parent=0 AND post_mime_type='image/jpeg'" --silent --skip-column-names))

# Function to delete posts in batches

delete_in_batches() {
    local batch=("$@")
    if ! wp post delete --force "${batch[@]}"; then
        echo "Error: Failed to delete one or more posts in this batch."
        exit 1
    fi
}

# Batch size

batch_size=500

# Total number of IDs

total_ids=${#ids[@]}

# Process IDs in batches of 500

for ((i=0; i<total_ids; i+=batch_size)); do
    batch=("${ids[@]:i:batch_size}")
    echo "Deleting batch starting with ID ${batch[0]}"
    delete_in_batches "T${batch[@]}"
done

echo "Deletion process completed."

Using scripts/batch-delete-unattached-jpegs.sh it is nearly 1.5x faster than the previous command. Don't forget to make the script executable by running chmod +x scripts/batch-delete-unattached-jpegs.sh.

Creating Dummy content

wp post generate --count=10

Deleting spam comments

wp comment list --status=spam --format=ids | xargs wp comment delete --force

Truly disabling/stopping comments

wp option update default_comment_status closed
wp option update default_ping_status closed
wp db query "UPDATE wp_posts SET comment_status='closed' WHERE post_status='publish';"
wp db query "UPDATE wp_posts SET ping_status='closed' WHERE post_status='publish';"

Cleaning your website

wp site empty

Checking the config file

wp config get

Checking the database size

wp db size --tables

Running core update

wp core update

Plugins manipulation

List

wp plugin list

Install

wp plugin install

Update

wp plugin update plugin-name

Disable

wp plugin deactivate plugin-name

Delete

wp plugin delete plugin-name

Reseting User Password

wp user update [email protected] --user_pass=new-password

Database Manipulations

Optimization

wp db optimize

Repair

wp db repair

Backup

wp db export name.sql

About

I often reference this list of useful WordPress CLI commands to enhance or clean up my sites.

Topics

Resources

License

Stars

Watchers

Forks

Languages