Using the wp comment command in the WordPress Command Line Interface (WP-CLI), you can manage the comments left by visitors on your blog pages.

To view, moderate, edit and delete comments using the WP-CLI, we recommend that you follow the instructions below.

 

How to VIEW comments using WP-CLI

One of the most important tasks in managing your WordPress blog is to view the comments that visitors/users write. This process is simple if we use WP-CLI commands from the command line. Follow the steps below to view comments using the wp comment command:

- Log in to the server via SSH with the cPanel user who owns the website for which you want to view WordPress comments

- Use the cd command to access the root folder of your website eg:

cd public_html/my_website

Replace public_html/my_website with the actual path to the root folder of your website.

Run the following command:

wp comment list

By default, this command will display a WordPress comment table for your website.

- Using the wp comment list command the following fields will be displayed by default for each comment:

comment_author_email

Although this information is useful, it does not provide the actual content of the comment. However, it provides the comment_ID needed to view the additional details of each comment.

Using comment_ID with the wp comment command, you can view the content of the comment. This is done by specifying comment_content as the field in your command.

An example of how to do this:

wp comment get $comment_ID –field=$field

Replace $comment_ID with the comment_ID value (from the previous step) of the comment for which you want to see details. To see the content of the comment, replace $field with the option: comment_content.

[email protected] [~/public_html]# wp comment get 1 --field=comment_content Hi, this is a comment. To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard. Commenter avatars come from <a href="https://gravatar.com" rel="nofollow">Gravatar</a>.

After reviewing the content of the comment, you can moderate it.

How to MODERATE comments using WP-CLI

Moderating comments is important if you have set Comment must be manually approved in WordPress’s Discussion Settings. When enabled, comments must be approved before being published on the website. It is a good precaution to take to avoid allowing visitors to post unwanted / unfiltered content in the comments section.

- Comments approval

- Log in to the server via SSH with the cPanel user who owns the website for which you want to moderate WordPress comments

- Use the cd command to access the root folder of your website eg:

cd public_html/my_website

Replace public_html/my_website with the actual path to the root folder of your website.

Locate comment_ID.

Run the following command:

wp comment approve $comment_ID

Replace $comment_ID with the comment_ID value of the comment for which you want to see details.

[email protected] [~/public_html]# wp comment approve 1
Success: Approved comment 1.

Since the comment was moderated and approved, it will now be displayed on the website. If you are moderating a comment that is obviously Spam, you can mark a comment as Spam using WP-CLI by following the steps below.

- Marking comments as Spam

- Log in to the server via SSH with the cPanel user who owns the website for which you want to moderate WordPress comments

- Use the cd command to access the root folder of your website eg:

cd public_html/my_website

Replace public_html/my_website with the actual path to the root folder of your website.

Locate comment_ID.

Run the following command:

wp comment spam $comment_ID

Replace $comment_ID with the comment_ID value of the comment for which you want to mark as Spam

[email protected] [~/public_html]# wp comment spam 2
Success: Marked as spam comment 2.

If you mark the comment as spam, it will not be displayed on the website. Marking comments as spam helps identify comments that can be deleted. If you accidentally mark a comment as Spam, you can uncheck it.

- Unmarking Spam

- Log in to the server via SSH with the cPanel user who owns the website for which you want to moderate WordPress comments

- Use the cd command to access the root folder of your website eg:

cd public_html/my_website

Replace public_html/my_website with the actual path to the root folder of your website.

Locate comment_ID.

Run the following command:

wp comment unspam $comment_ID

Replace $comment_ID with the comment_ID value of the comment for which you want to unmark Spam.

[email protected] [~/public_html]# wp comment unspam 2
Success: Unspammed comment 2.

How to EDIT comments using WP-CLI

Using the wp comment command you can edit various fields to update the comment details. Follow these steps to edit a comment:
 

- Log in to the server via SSH with the cPanel user who owns the website for which you want to edit WordPress comments

- Use the cd command to access the root folder of your website eg:

cd public_html/my_website

Replace public_html/my_website with the actual path to the root folder of your website.

Locate comment_ID.

Run the following command:

wp comment update $comment_ID —$field=$value

Replace $comment_ID with the comment_ID value of the comment you want to edit. See the table below for the optional $field that you can update to the $value you want using WP-CLI.

[email protected][~/public_html]# wp comment update 4 --comment_author=A WP Admin
Success: Updated comment 4.

You can update any of the available fields using the same method.

How to DELETE comments using WP-CLI

Deleting comments is just as easy.

- Log in to the server via SSH with the cPanel user who owns the website for which you want to delete WordPress comments

- Use the cd command to access the root folder of your website eg:

cd public_html/my_website

Replace public_html/my_website with the actual path to the root folder of your website.

Locate comment_ID.

Run the following command:

wp comment delete $comment_ID

Replace $comment_ID with the comment_ID value of the comment you want to delete.

[email protected][~/public_html]# wp comment delete 2 
Success: Trashed comment 2.

 

For assistance in applying the above instructions on HostX servers please contact us. HostX offers the fastest WordPress hosting and can help you solve your problems.

Cette réponse était-elle pertinente? 0 Utilisateurs l'ont trouvée utile (0 Votes)