Skip to content

Instantly share code, notes, and snippets.

@ptasker
Created May 11, 2017 18:01
Show Gist options
  • Save ptasker/1c8e5affd1e214263cbe3bc1bcbfe09a to your computer and use it in GitHub Desktop.
Save ptasker/1c8e5affd1e214263cbe3bc1bcbfe09a to your computer and use it in GitHub Desktop.
WP CLI remove all media
#!/usr/bin/env bash
DIR="$1"
if [ -z "$1" ]
then
echo "Usage: $0 {WP install dir path}"
exit 1
fi
cd $DIR
pwd
wp post delete $(wp post list --post_type='attachment' --format=ids)
@khoipro
Copy link

khoipro commented Feb 21, 2025

This one is better.

wp post delete $(wp post list --post_type='attachment' --format=ids --posts_per_page=1000) --force
  • force: no more storage on Storage
  • posts_per_page: avoid to display 'too long' in case you have too much media

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment