Skip to content

Instantly share code, notes, and snippets.

@MaximeCulea
Last active July 17, 2024 01:26
Show Gist options
  • Save MaximeCulea/dbd5835a01d2b4e6a6544919db3f26a0 to your computer and use it in GitHub Desktop.
Save MaximeCulea/dbd5835a01d2b4e6a6544919db3f26a0 to your computer and use it in GitHub Desktop.
A list of WordPress WP Cli commands.
#!/usr/bin/env bash
# Related to WP CLI in Multisite check following link
# @see https://gist.github.com/MaximeCulea/575e493a061359edbb12cefc3aa4c770
# Update all post's thumnbail
wp post update $(wp post list --format=ids --post_type=post) --post_type=post --meta_input='{"_thumbnail_id":"160"}'
# Generate and add dummy thumbnails to a wanted post type : https://gist.github.com/MaximeCulea/c04e62c4b6e79b4e4e17b73dd023b6c4
# Search Replace with regex
# Regex will match content <div style="position: absolute; </div> with multilignes
# @see https://regex101.com/r/dT69HM/3
wp search-replace "<div style=['|\"]position: absolute;(.|\n)*</div>" " " wp_posts --regex --regex-flags='U' --include-columns=post_content
# Change the post type from one to another
for post_id in $(wp post list --post_type="program" --format=ids); do wp post update $post_id --post_type="e-program"; done;
# Also migrate terms in another taxonomy, but preserving assignation with posts
# The posts needs to have acces to old and new taxonomy, if not, you may change the source taxonomy to be transversal in order for the command lign to work
for term_id in $(wp term list category --format=ids); do wp term migrate $term_id --from=category --to=ss_category; done;
# Force to empty the Trash
wp post delete $(wp post list --post_status=trash --format=ids)
# Delete all posts from on post type
wp post delete $(wp post list --post_type="press" --format=ids) --force --defer-term-counting
## Export DB with SRDB done, for exemple http -> https
# make the srdb and export it into a sql
wp search-replace http://maximeculea.fr https://maximeculea.fr --all-tables --export=2020-03-11-https.sql
# When ready import the freshly db export
wp db import 2020-03-11-https.sql
## Update WordPress Admin without email
# To list admin user
wp option list --search="admin_email"
# To update admin user
wp option update admin_email mculea@wideagency.ch
## Woo optimized Action Scheduler queue
# See https://actionscheduler.org/wp-cli/
wp action-scheduler run
# Generate the pot from all the code and templating engine
# @see https://developer.wordpress.org/cli/commands/i18n/make-pot/
# specify the path to the wanted pot, for which domain name slug and ignoring uploads files to be parsed
wp i18n make-pot ./ {path_to}/theme.pot --slug={slug} --exclude={path_to}/uploads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment