Skip to content

Instantly share code, notes, and snippets.

@ptasker
Created May 11, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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)
@ramonfincken
Copy link

use --force to physically delete the media from your server storage

@gaptekupdate
Copy link

Add allow-root

wp post delete --force --allow-root $(wp post list --post_type='attachment' --format=ids --allow-root)

@ypsilon-p
Copy link

@gaptekupdate - You never should run the WP CLI as root user. Instead of this, you can create a service user, which has only the permissions for the cli and its required permissions.

@karpalig
Copy link

karpalig commented Jan 4, 2024

@ypsilon-p

Error: Parameter errors:
unknown --post_type parameter
unknown --format parameter
unknown --allow-root) parameter

Kindly help me to solve it

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