wp comment

Creates, updates, deletes, and moderates comments.

Subcommands

Command Description
wp comment approve Approves a comment.
wp comment count Counts comments, on whole blog or on a given post.
wp comment create Creates a new comment.
wp comment delete Deletes a comment.
wp comment exists Verifies whether a comment exists.
wp comment generate Generates some number of new dummy comments.
wp comment get Gets the data of a single comment.
wp comment list Gets a list of comments.
wp comment meta Adds, updates, deletes, and lists comment custom fields.
wp comment recount Recalculates the comment_count value for one or more posts.
wp comment spam Marks a comment as spam.
wp comment status Gets the status of a comment.
wp comment trash Trashes a comment.
wp comment unapprove Unapproves a comment.
wp comment unspam Unmarks a comment as spam.
wp comment untrash Untrashes a comment.
wp comment update Updates one or more comments.

Examples

# Create a new comment.
$ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli"
Success: Created comment 932.

# Update an existing comment.
$ wp comment update 123 --comment_author='That Guy'
Success: Updated comment 123.

# Delete an existing comment.
$ wp comment delete 1337 --force
Success: Deleted comment 1337.

# Trash all spam comments.
$ wp comment delete $(wp comment list --status=spam --format=ids)
Success: Trashed comment 264.
Success: Trashed comment 262.

wp comment approve

Approves a comment.

Synopsis

wp comment approve <id>...

Parameters

Parameter Description
<id>... The IDs of the comments to approve.

Examples

$ wp comment approve 1337
Success: Approved comment 1337.

wp comment count

Counts comments, on whole blog or on a given post.

Synopsis

wp comment count [<post-id>]

Parameters

Parameter Description
[<post-id>] The ID of the post to count comments in.

Examples

# Count comments on whole blog.
$ wp comment count
approved:        33
spam:            3
trash:           1
post-trashed:    0
all:             34
moderated:       1
total_comments:  37

# Count comments in a post.
$ wp comment count 42
approved:        19
spam:            0
trash:           0
post-trashed:    0
all:             19
moderated:       0
total_comments:  19

wp comment create

Creates a new comment.

Synopsis

wp comment create [--<field>=<value>] [--porcelain]

Parameters

Parameter Description
[--<field>=<value>] Associative args for the new comment. See wp_insert_comment().
[--porcelain] Output just the new comment id.

Examples

$ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli"
Success: Created comment 932.

wp comment delete

Deletes a comment.

Synopsis

wp comment delete <id>... [--force]

Parameters

Parameter Description
<id>... One or more IDs of comments to delete.
[--force] Skip the trash bin.

Examples

# Delete comment.
$ wp comment delete 1337 --force
Success: Deleted comment 1337.

# Delete multiple comments.
$ wp comment delete 1337 2341 --force
Success: Deleted comment 1337.
Success: Deleted comment 2341.

wp comment exists

Verifies whether a comment exists. Displays a success message if the comment does exist.

Synopsis

wp comment exists <id>

Parameters

Parameter Description
<id> The ID of the comment to check.

Examples

$ wp comment exists 1337
Success: Comment with ID 1337 exists.

wp comment generate

Generates some number of new dummy comments. Creates a specified number of new comments with dummy data.

Synopsis

wp comment generate [--count=<number>] [--post_id=<post-id>] [--format=<format>]

Parameters

Parameter Description
[--count=<number>] How many comments to generate? Default: 100
[--post_id=<post-id>] Assign comments to a specific post.
[--format=<format>] Render output in a particular format. Default: progress. Options: progress, ids

Examples

# Generate comments for the given post.
$ wp comment generate --format=ids --count=3 --post_id=123
138 139 140

# Add meta to every generated comment.
$ wp comment generate --format=ids --count=3 | xargs -d ' ' -I % wp comment meta add % foo bar
Success: Added custom field.
Success: Added custom field.
Success: Added custom field.

wp comment get

Gets the data of a single comment.

Synopsis

wp comment get <id> [--field=<field>] [--fields=<fields>] [--format=<format>]

Parameters

Parameter Description
<id> The comment to get.
[--field=<field>] Instead of returning the whole comment, returns the value of a single field.
[--fields=<fields>] Limit the output to specific fields. Defaults to all fields.
[--format=<format>] Render output in a particular format. Default: table. Options: table, csv, json, yaml

Examples

$ wp comment get 21 --field=content
Thanks for all the comments, everyone!

wp comment list

Gets a list of comments.

Display comments based on all arguments supported by WP_Comment_Query().

Synopsis

wp comment list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]

Parameters

Parameter Description
[--<field>=<value>] One or more args to pass to WP_Comment_Query.
[--field=<field>] Prints the value of a single field for each comment.
[--fields=<fields>] Limit the output to specific object fields.
[--format=<format>] Render output in a particular format. Default: table. Options: table, ids, csv, json, count, yaml

Available Fields

Default fields:

  • comment_ID
  • comment_post_ID
  • comment_date
  • comment_approved
  • comment_author
  • comment_author_email

Optional fields:

  • comment_author_url
  • comment_author_IP
  • comment_date_gmt
  • comment_content
  • comment_karma
  • comment_agent
  • comment_type
  • comment_parent
  • user_id
  • url

Examples

# List comment IDs.
$ wp comment list --field=ID
22
23
24

# List comments of a post.
$ wp comment list --post_id=1 --fields=ID,comment_date,comment_author
+------------+---------------------+----------------+
| comment_ID | comment_date        | comment_author |
+------------+---------------------+----------------+
| 1          | 2015-06-20 09:00:10 | Mr WordPress   |
+------------+---------------------+----------------+

# List approved comments.
$ wp comment list --number=3 --status=approve --fields=ID,comment_date,comment_author

# List unapproved comments.
$ wp comment list --number=3 --status=hold --fields=ID,comment_date,comment_author

# List comments marked as spam.
$ wp comment list --status=spam --fields=ID,comment_date,comment_author

# List comments in trash.
$ wp comment list --status=trash --fields=ID,comment_date,comment_author

wp comment meta

Adds, updates, deletes, and lists comment custom fields.

Subcommands

Command Description
wp comment meta add Add a meta field.
wp comment meta delete Delete a meta field.
wp comment meta get Get meta field value.
wp comment meta list List all metadata associated with an object.
wp comment meta patch Update a nested value for a meta field.
wp comment meta pluck Get a nested value from a meta field.
wp comment meta update Update a meta field.

Examples

# Set comment meta
$ wp comment meta set 123 description "Mary is a WordPress developer."
Success: Updated custom field 'description'.

# Get comment meta
$ wp comment meta get 123 description
Mary is a WordPress developer.

# Update comment meta
$ wp comment meta update 123 description "Mary is an awesome WordPress developer."
Success: Updated custom field 'description'.

# Delete comment meta
$ wp comment meta delete 123 description
Success: Deleted custom field.

wp comment recount

Recalculates the comment_count value for one or more posts.

Synopsis

wp comment recount <id>...

Parameters

Parameter Description
<id>... IDs for one or more posts to update.

Examples

$ wp comment recount 123
Updated post 123 comment count to 67.

wp comment spam

Marks a comment as spam.

Synopsis

wp comment spam <id>...

Parameters

Parameter Description
<id>... The IDs of the comments to mark as spam.

Examples

$ wp comment spam 1337
Success: Marked as spam comment 1337.

wp comment status

Gets the status of a comment.

Synopsis

wp comment status <id>

Parameters

Parameter Description
<id> The ID of the comment to check.

Examples

$ wp comment status 1337
approved

wp comment trash

Trashes a comment.

Synopsis

wp comment trash <id>...

Parameters

Parameter Description
<id>... The IDs of the comments to trash.

Examples

$ wp comment trash 1337
Success: Trashed comment 1337.

wp comment unapprove

Unapproves a comment.

Synopsis

wp comment unapprove <id>...

Parameters

Parameter Description
<id>... The IDs of the comments to unapprove.

Examples

$ wp comment unapprove 1337
Success: Unapproved comment 1337.

wp comment unspam

Unmarks a comment as spam.

Synopsis

wp comment unspam <id>...

Parameters

Parameter Description
<id>... The IDs of the comments to unmark as spam.

Examples

$ wp comment unspam 1337
Success: Unspammed comment 1337.

wp comment untrash

Untrashes a comment.

Synopsis

wp comment untrash <id>...

Parameters

Parameter Description
<id>... The IDs of the comments to untrash.

Examples

$ wp comment untrash 1337
Success: Untrashed comment 1337.

wp comment update

Updates one or more comments.

Synopsis

wp comment update <id>... --<field>=<value>

Parameters

Parameter Description
<id>... One or more IDs of comments to update.
--<field>=<value> One or more fields to update. See wp_update_comment().

Examples

$ wp comment update 123 --comment_author='That Guy'
Success: Updated comment 123.