Skip to content

Instantly share code, notes, and snippets.

@dangtrinhnt
Last active May 5, 2024 15:19
Show Gist options
  • Save dangtrinhnt/561698963c88affb4992 to your computer and use it in GitHub Desktop.
Save dangtrinhnt/561698963c88affb4992 to your computer and use it in GitHub Desktop.
Delete all pending comment using WP-CLI
#! /bin/bash
for blog_path in $(wp site list --field=path)
do
path_wo_slashes="${blog_path////""}"
url="http://your.blog.address/$path_wo_slashes"
# status = approve, hold, trash, spam
tmp_ids=$(wp comment list --status=hold --format=ids --url=$url)
# clean the string
pending_ids="$(echo -e "${tmp_ids}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
if [ ! -z "$pending_ids" -a "$pending_ids" != " " ]; then
wp comment delete $pending_ids --url=$url --force
fi
done
@wuxmedia
Copy link

wuxmedia commented May 6, 2020

$ wp comment trash $(wp comment list --status=hold --format=ids)

@jauhari
Copy link

jauhari commented Sep 2, 2023

$ wp comment trash $(wp comment list --status=hold --format=ids)

this one SOLVE my Problem. Thanks

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