LoginSignup
0
0

More than 5 years have passed since last update.

WP-CLIで特定投稿のコメントのみ削除する

Posted at

考え方

$ wp comment delete COMMENT_ID
でコメントを削除できるので、COMMENT_IDに該当記事についているコメントを入れるようにする。

参考:スパムコメントの全削除

# delete all spam comments.
# from http://wp-cli.org/commands/comment/
$ wp comment delete $(wp comment list --status=spam --format=ids)

投稿IDからのコメントリスト取得

$ wp comment list --post_id=2
[vagrant@wp-theme ~]$ wp comment list
+------------+-----------------+---------------------+------------------+------------------------------------------------------------------------------------------------+----------------------------+
| comment_ID | comment_post_ID | comment_date        | comment_approved | comment_author                                                                                 | comment_author_email       |
+------------+-----------------+---------------------+------------------+------------------------------------------------------------------------------------------------+----------------------------+
| 1          | 2               | 2015-09-13 06:39:14 | 1                | Mr WordPress                                                                                   |                            |
| 30         | 2            | 2013-03-14 12:35:07 | 1                | John Doe                                                                                       | example@example.org        |

組み合わせるとこうなる

投稿IDさえわかっていれば以下のコマンドで該当記事のコメントのみ全削除が可能

$ wp comment delete $(wp comment list --post_id=2)
0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0