Last active
May 5, 2024 15:19
-
-
Save dangtrinhnt/561698963c88affb4992 to your computer and use it in GitHub Desktop.
Delete all pending comment using WP-CLI
This file contains 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 | |
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 |
$ 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
$ wp comment trash $(wp comment list --status=hold --format=ids)