Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Last active November 7, 2023 03:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetwopct/cbbd7c2da7a01203f3dc64aed42b4a4a to your computer and use it in GitHub Desktop.
Save thetwopct/cbbd7c2da7a01203f3dc64aed42b4a4a to your computer and use it in GitHub Desktop.
WordPress WP-CLI cheat sheet
# WordPress WP-CLI cheat sheet
# Reset everything in case of bugs
wp transient delete --all && wp rewrite flush && wp cache flush
# or in Lando
lando wp transient delete --all && lando wp rewrite flush && lando wp cache flush
# reset a new install
wp plugin delete $(wp plugin list --status=inactive --field=name)
wp theme delete $(wp theme list --status=inactive --field=name)
wp widget delete $(wp widget list wp_inactive_widgets --format=ids)
wp widget reset --all
wp site empty
# remove 2019
wp theme delete twentynineteen
# Update options to be optimised
wp option update date_format "j F Y"
wp option update default_comment_status "closed"
wp option update thread_comments 0
wp option update show_avatars 0
wp option update comment_moderation 1
wp option update permalink_structure "/%postname%/"
# Delete all transients.
$ wp transient delete --all
# install favourite plugins
wp plugin install classic-editor --activate
wp plugin install debug-bar --activate
wp plugin install imsanity --activate
wp plugin install query-monitor --activate
wp plugin install regenerate-thumbnails --activate
wp plugin install safe-svg --activate
wp plugin install wordpress-seo --activate
wp plugin install litespeed-cache
wp plugin install worker
wp plugin install acf-content-analysis-for-yoast-seo
wp plugin install acf-extended
wp plugin install prevent-browser-caching --activate
wp plugin install heartbeat-control --activate
wp plugin install advanced-access-manager
# find and replace
wp search-replace <old> <new>
wp search-replace <old> <new> --dry-run
wp search-replace http://domain.com http://dev.domain.com
wp search-replace https://domain.com http://dev.domain.com
# do http https dev
wp db import database.sql
# database with filename as the day in unix format
wp db export `date +"%Y%m%d"`.sql --porcelain
wp db export db.sql --porcelain
# zipping up a SQL file to .zip
zip db.zip db.sql
# cleanup once done
rm db.zip && rm db.sql
# Flush rewrite rules
wp rewrite flush
# Flush cache
wp cache flush
# user create
wp user create admin_name email@hotmail.co.uk --role=administrator
# regenerate thumbnails
wp media regenerate --yes
wp media regenerate --yes --only-missing
wp media regenerate --image_size=custom_thumb
# delete all revisions
wp post delete $(wp post list --post_type='revision' --format=ids) --force
# not sure of options? Put this on end of any command
--prompt
# gets wp-config.php settings
wp config get
wp config list
# pull remote db with wp-cli
# https://jmichaelward.com/using-wp-cli-to-import-a-remote-database/
wp @production db export - | lando wp db import - && lando wp search-replace "https://www.current.com" "https://new.lndo.site"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment