Created
July 8, 2025 16:36
-
-
Save patrickcoombe/8e0f619679c74bfc0942b58736783c08 to your computer and use it in GitHub Desktop.
Bash Script Bulk Delete URLs in WP Using WP CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while IFS= read -r url; do | |
# use sed to parse the URL since it really only needs the slug I could have done this manually instead but whatever | |
# also note make sure you have a file called urls.txt with the right perms with the URLs you wanna delete | |
slug=$(echo "$url" | sed 's|.*/||; s|/$||') | |
# Find post ID by slug | |
post_id=$(wp post list --post_name="$slug" --field=ID --post_status=any) | |
if [ ! -z "$post_id" ]; then | |
wp post delete "$post_id" --force | |
echo "Deleted: $url (ID: $post_id)" | |
else | |
echo "Not found: $url" | |
fi | |
done < urls.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment