Skip to content

Instantly share code, notes, and snippets.

@sp4r74cus
Last active August 22, 2018 09:40
Show Gist options
  • Save sp4r74cus/491b44d9b98a619847071382850314ba to your computer and use it in GitHub Desktop.
Save sp4r74cus/491b44d9b98a619847071382850314ba to your computer and use it in GitHub Desktop.
Query for old posts and update their date fields. Requires the wp-cli-restful package (https://wp-cli.org/restful/).
# Linux
wp post update $(wp rest post list --before="`date -u +%Y-%m-%dT%H:%M:%SZ -d "1 year ago"`" \
--format=ids --per_page=1) --post_date="`date '+%Y-%m-%d %H:%M:%S'`" --post_date_gmt="`date -u '+%Y-%m-%d %H:%M:%S'`" \
--post_modified="`date '+%Y-%m-%d %H:%M:%S'`" --post_modified_gmt="`date -u '+%Y-%m-%d %H:%M:%S'`"
# Mac OSX
wp post update $(wp rest post list --before="`date -v -1y +%Y-%m-%dT%H:%M:%SZ`" \
--format=ids --per_page=1) --post_date="`date '+%Y-%m-%d %H:%M:%S'`" --post_date_gmt="`date -u '+%Y-%m-%d %H:%M:%S'`" \
--post_modified="`date '+%Y-%m-%d %H:%M:%S'`" --post_modified_gmt="`date -u '+%Y-%m-%d %H:%M:%S'`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment