wp comment
Creates, updates, deletes, and moderates comments.
Commands | Description |
---|---|
wp comment create | Creates a new comment. |
wp comment update | Updates one or more comments. |
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 delete | Deletes a comment. |
wp comment trash | Trashes a comment. |
wp comment untrash | Untrashes a comment. |
wp comment spam | Marks a comment as spam. |
wp comment unspam | Unmarks a comment as spam. |
wp comment approve | Approves a comment. |
wp comment unapprove | Unapproves a comment. |
wp comment count | Counts comments, on whole blog or on a given post. |
wp comment recount | Recalculates the comment_count value for one or more posts. |
wp comment status | Gets the status of a comment. |
wp comment exists | Verifies whether a comment exists. |
wp comment meta list | List all metadata associated with an object. |
wp comment meta get | Get meta field value. |
wp comment meta delete | Delete a meta field. |
wp comment meta add | Add a meta field. |
wp comment meta update | Update a meta field. |
wp comment meta pluck | Get a nested value from a meta field. |
wp comment meta patch | Update a nested value for a meta field. |
Examples
wp comment
# 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. # Delete all spam comments. $ wp comment delete $(wp comment list --status=spam --format=ids) Success: Deleted comment 264. Success: Deleted comment 262.
wp comment meta
# 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.
Source code of the commands
wp comment create
Creates a new comment.
Usage
wp comment create [--{field}={value}] [--porcelain]
You can specify global options and the following:
- [--{field}={value}]
- Associative args for the new comment. See wp_insert_comment().
- [--porcelain]
- Output just the new comment id.
Examples
# Create comment. $ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli" Success: Created comment 932.
wp comment update
Updates one or more comments.
Usage
wp comment update {id}... --{field}={value}
You can specify global options and the following:
- {id}...
- One or more IDs of comments to update.
- --{field}={value}
- One or more fields to update. See wp_update_comment().
Examples
# Update comment. $ wp comment update 123 --comment_author='That Guy' Success: Updated comment 123.
wp comment generate
Generates some number of new dummy comments.
Creates a specified number of new comments with dummy data.
Usage
wp comment generate [--count={number}] [--post_id={post-id}] [--format={format}]
You can specify global options and the following:
- [--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
Can be:- 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.
Usage
wp comment get {id} [--field={field}] [--fields={fields}] [--format={format}]
You can specify global options and the following:
- {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
Can be:- table
- csv
- json
- yaml
Examples
# Get comment. $ wp comment get 21 --field=content Thanks for all the comments, everyone!
wp comment list
Gets a list of comments.
Usage
wp comment list [--{field}={value}] [--field={field}] [--fields={fields}] [--format={format}]
You can specify global options and the following:
- [--{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
Can be:- table
- ids
- csv
- json
- count
- yaml
Available fields
These fields will be displayed by default for each comment:
- comment_ID
- comment_post_ID
- comment_date
- comment_approved
- comment_author
- comment_author_email
These fields are optionally available:
- 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 +------------+---------------------+----------------+ | comment_ID | comment_date | comment_author | +------------+---------------------+----------------+ | 1 | 2015-06-20 09:00:10 | Mr WordPress | | 30 | 2013-03-14 12:35:07 | John Doe | | 29 | 2013-03-14 11:56:08 | Jane Doe | +------------+---------------------+----------------+
wp comment delete
Deletes a comment.
Usage
wp comment delete {id}... [--force]
You can specify global options and the following:
- {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 trash
Trashes a comment.
Usage
wp comment trash {id}...
You can specify global options and the following:
- {id}...
- The IDs of the comments to trash.
Examples
# Trash comment. $ wp comment trash 1337 Success: Trashed comment 1337.
wp comment untrash
Untrashes a comment.
Usage
wp comment untrash {id}...
You can specify global options and the following:
- {id}...
- The IDs of the comments to untrash.
Examples
# Untrash comment. $ wp comment untrash 1337 Success: Untrashed comment 1337.
wp comment spam
Marks a comment as spam.
Usage
wp comment spam {id}...
You can specify global options and the following:
- {id}...
- The IDs of the comments to mark as spam.
Examples
# Spam comment. $ wp comment spam 1337 Success: Marked as spam comment 1337.
wp comment unspam
Unmarks a comment as spam.
Usage
wp comment unspam {id}...
You can specify global options and the following:
- {id}...
- The IDs of the comments to unmark as spam.
Examples
# Unspam comment. $ wp comment unspam 1337 Success: Unspammed comment 1337.
wp comment approve
Approves a comment.
Usage
wp comment approve {id}...
You can specify global options and the following:
- {id}...
- The IDs of the comments to approve.
Examples
# Approve comment. $ wp comment approve 1337 Success: Approved comment 1337.
wp comment unapprove
Unapproves a comment.
Usage
wp comment unapprove {id}...
You can specify global options and the following:
- {id}...
- The IDs of the comments to unapprove.
Examples
# Unapprove comment. $ wp comment unapprove 1337 Success: Unapproved comment 1337.
wp comment count
Counts comments, on whole blog or on a given post.
Usage
wp comment count [{post-id}]
You can specify global options and the following:
- [{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 recount
Recalculates the comment_count value for one or more posts.
Usage
wp comment recount {id}...
You can specify global options and the following:
- {id}...
- IDs for one or more posts to update.
Examples
# Recount comment for the post. $ wp comment recount 123 Updated post 123 comment count to 67.
wp comment status
Gets the status of a comment.
Usage
wp comment status {id}
You can specify global options and the following:
- {id}
- The ID of the comment to check.
Examples
# Get status of comment. $ wp comment status 1337 approved
wp comment exists
Verifies whether a comment exists.
Displays a success message if the comment does exist.
Usage
wp comment exists {id}
You can specify global options and the following:
- {id}
- The ID of the comment to check.
Examples
# Check whether comment exists. $ wp comment exists 1337 Success: Comment with ID 1337 exists.
wp comment meta list
List all metadata associated with an object.
Usage
wp comment meta list {id} [--keys={keys}] [--fields={fields}] [--format={format}] [--orderby={fields}] [--order={order}]
You can specify global options and the following:
- {id}
- ID for the object.
- [--keys={keys}]
- Limit output to metadata of specific keys.
- [--fields={fields}]
- Limit the output to specific row fields. Defaults to id,meta_key,meta_value.
- [--format={format}]
Render output in a particular format.
Default: table
Can be:- table
- csv
- json
- yaml
- count
- [--orderby={fields}]
Set orderby which field.
Default: id
Can be:- id
- meta_key
- meta_value
- [--order={order}]
Set ascending or descending order.
Default: asc
Can be:- asc
- desc
wp comment meta get
Get meta field value.
Usage
wp comment meta get {id} {key} [--format={format}]
You can specify global options and the following:
- {id}
- The ID of the object.
- {key}
- The name of the meta field to get.
- [--format={format}]
Get value in a particular format.
Default: var_export
Can be:- var_export
- json
- yaml
wp comment meta delete
Delete a meta field.
Usage
wp comment meta delete {id} [{key}] [{value}] [--all]
You can specify global options and the following:
- {id}
- The ID of the object.
- [{key}]
- The name of the meta field to delete.
- [{value}]
- The value to delete. If omitted, all rows with key will deleted.
- [--all]
- Delete all meta for the object.
wp comment meta add
Add a meta field.
Usage
wp comment meta add {id} {key} [{value}] [--format={format}]
You can specify global options and the following:
- {id}
- The ID of the object.
- {key}
- The name of the meta field to create.
- [{value}]
- The value of the meta field. If omitted, the value is read from STDIN.
- [--format={format}]
The serialization format for the value.
Default: plaintext
Can be:- plaintext
- json
wp comment meta update
Update a meta field.
Usage
wp comment meta update {id} {key} [{value}] [--format={format}]
You can specify global options and the following:
- {id}
- The ID of the object.
- {key}
- The name of the meta field to update.
- [{value}]
- The new value. If omitted, the value is read from STDIN.
- [--format={format}]
The serialization format for the value.
Default: plaintext
Can be:- plaintext
- json
wp comment meta pluck
Get a nested value from a meta field.
Usage
wp comment meta pluck {id} {key} {key-path}... [--format={format}]
You can specify global options and the following:
- {id}
- The ID of the object.
- {key}
- The name of the meta field to get.
- {key-path}...
- The name(s) of the keys within the value to locate the value to pluck.
- [--format={format}]
The output format of the value.
Default: plaintext
Can be:- plaintext
- json
- yaml
wp comment meta patch
Update a nested value for a meta field.
Usage
wp comment meta patch {action} {id} {key} {key-path}... [{value}] [--format={format}]
You can specify global options and the following:
- {action}
Patch action to perform.
Can be:
- insert
- update
- delete
- {id}
- The ID of the object.
- {key}
- The name of the meta field to update.
- {key-path}...
- The name(s) of the keys within the value to locate the value to patch.
- [{value}]
- The new value. If omitted, the value is read from STDIN.
- [--format={format}]
The serialization format for the value.
Default: plaintext
Can be:- plaintext
- json