Skip to content

Instantly share code, notes, and snippets.

@zevilz
Last active March 21, 2023 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zevilz/b4f61b0ab82f3b6f146db89bc7dc1000 to your computer and use it in GitHub Desktop.
Save zevilz/b4f61b0ab82f3b6f146db89bc7dc1000 to your computer and use it in GitHub Desktop.
Remove old WP attachments
#!/bin/bash
while true; do
POSTS=$(wp db query 'SELECT ID FROM wp_posts WHERE post_type="attachment" AND post_date < "2022-06-05" LIMIT 10000;' --skip-column-names | paste -s -d ' ' -)
if ! [ -z "$POSTS" ]; then
wp post delete $POSTS --force
else
exit 0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment