An open API service indexing awesome lists of open source software.

https://github.com/wp-cli/entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
https://github.com/wp-cli/entity-command

cli comment entity hacktoberfest menu meta network option page post session site taxonomy term user wordpress wp-cli wp-cli-package

Last synced: 27 days ago
JSON representation

Manage WordPress comments, menus, options, posts, sites, terms, and users.

Awesome Lists containing this project

README

        

wp-cli/entity-command
=====================

Manage WordPress comments, menus, options, posts, sites, terms, and users.

[![Testing](https://github.com/wp-cli/entity-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/entity-command/actions/workflows/testing.yml)

Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)

## Using

This package implements the following commands:

### wp comment

Creates, updates, deletes, and moderates comments.

~~~
wp comment
~~~

**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.

~~~
wp comment approve ...
~~~

**OPTIONS**

...
The IDs of the comments to approve.

**EXAMPLES**

# Approve comment.
$ wp comment approve 1337
Success: Approved comment 1337.

### wp comment count

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

~~~
wp comment count []
~~~

**OPTIONS**

[]
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.

~~~
wp comment create [--=] [--porcelain]
~~~

**OPTIONS**

[--=]
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 delete

Deletes a comment.

~~~
wp comment delete ... [--force]
~~~

**OPTIONS**

...
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.

~~~
wp comment exists
~~~

Displays a success message if the comment does exist.

**OPTIONS**


The ID of the comment to check.

**EXAMPLES**

# Check whether comment exists.
$ wp comment exists 1337
Success: Comment with ID 1337 exists.

### wp comment generate

Generates some number of new dummy comments.

~~~
wp comment generate [--count=] [--post_id=] [--format=]
~~~

Creates a specified number of new comments with dummy data.

**OPTIONS**

[--count=]
How many comments to generate?
---
default: 100
---

[--post_id=]
Assign comments to a specific post.

[--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.

~~~
wp comment get [--field=] [--fields=] [--format=]
~~~

**OPTIONS**


The comment to get.

[--field=]
Instead of returning the whole comment, returns the value of a single field.

[--fields=]
Limit the output to specific fields. Defaults to all fields.

[--format=]
Render output in a particular format.
---
default: table
options:
- 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.

~~~
wp comment list [--=] [--field=] [--fields=] [--format=]
~~~

Display comments based on all arguments supported by
[WP_Comment_Query()](https://developer.wordpress.org/reference/classes/WP_Comment_Query/__construct/).

**OPTIONS**

[--=]
One or more args to pass to WP_Comment_Query.

[--field=]
Prints the value of a single field for each comment.

[--fields=]
Limit the output to specific object fields.

[--format=]
Render output in a particular format.
---
default: table
options:
- 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 |
+------------+---------------------+----------------+

# List unapproved comments.
$ wp comment list --number=3 --status=hold --fields=ID,comment_date,comment_author
+------------+---------------------+----------------+
| comment_ID | comment_date | comment_author |
+------------+---------------------+----------------+
| 8 | 2023-11-10 13:13:06 | John Doe |
| 7 | 2023-11-10 13:09:55 | Mr WordPress |
| 9 | 2023-11-10 11:22:31 | Jane Doe |
+------------+---------------------+----------------+

# List comments marked as spam.
$ wp comment list --status=spam --fields=ID,comment_date,comment_author
+------------+---------------------+----------------+
| comment_ID | comment_date | comment_author |
+------------+---------------------+----------------+
| 2 | 2023-11-10 11:22:31 | Jane Doe |
+------------+---------------------+----------------+

# List comments in trash.
$ wp comment list --status=trash --fields=ID,comment_date,comment_author
+------------+---------------------+----------------+
| comment_ID | comment_date | comment_author |
+------------+---------------------+----------------+
| 3 | 2023-11-10 11:22:31 | John Doe |
+------------+---------------------+----------------+

### wp comment meta

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

~~~
wp comment meta
~~~

**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 meta add

Add a meta field.

~~~
wp comment meta add [] [--format=]
~~~

**OPTIONS**


The ID of the object.


The name of the meta field to create.

[]
The value of the meta field. If omitted, the value is read from STDIN.

[--format=]
The serialization format for the value.
---
default: plaintext
options:
- plaintext
- json
---

### wp comment meta delete

Delete a meta field.

~~~
wp comment meta delete [] [] [--all]
~~~

**OPTIONS**


The ID of the object.

[]
The name of the meta field to delete.

[]
The value to delete. If omitted, all rows with key will deleted.

[--all]
Delete all meta for the object.

### wp comment meta get

Get meta field value.

~~~
wp comment meta get [--format=]
~~~

**OPTIONS**


The ID of the object.


The name of the meta field to get.

[--format=]
Get value in a particular format.
---
default: var_export
options:
- var_export
- json
- yaml
---

### wp comment meta list

List all metadata associated with an object.

~~~
wp comment meta list [--keys=] [--fields=] [--format=] [--orderby=] [--order=] [--unserialize]
~~~

**OPTIONS**


ID for the object.

[--keys=]
Limit output to metadata of specific keys.

[--fields=]
Limit the output to specific row fields. Defaults to id,meta_key,meta_value.

[--format=]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- yaml
- count
---

[--orderby=]
Set orderby which field.
---
default: id
options:
- id
- meta_key
- meta_value
---

[--order=]
Set ascending or descending order.
---
default: asc
options:
- asc
- desc
---

[--unserialize]
Unserialize meta_value output.

### wp comment meta patch

Update a nested value for a meta field.

~~~
wp comment meta patch ... [] [--format=]
~~~

**OPTIONS**


Patch action to perform.
---
options:
- insert
- update
- delete
---


The ID of the object.


The name of the meta field to update.

...
The name(s) of the keys within the value to locate the value to patch.

[]
The new value. If omitted, the value is read from STDIN.

[--format=]
The serialization format for the value.
---
default: plaintext
options:
- plaintext
- json
---

### wp comment meta pluck

Get a nested value from a meta field.

~~~
wp comment meta pluck ... [--format=]
~~~

**OPTIONS**


The ID of the object.


The name of the meta field to get.

...
The name(s) of the keys within the value to locate the value to pluck.

[--format=]
The output format of the value.
---
default: plaintext
options:
- plaintext
- json
- yaml

### wp comment meta update

Update a meta field.

~~~
wp comment meta update [] [--format=]
~~~

**OPTIONS**


The ID of the object.


The name of the meta field to update.

[]
The new value. If omitted, the value is read from STDIN.

[--format=]
The serialization format for the value.
---
default: plaintext
options:
- plaintext
- json
---

### wp comment recount

Recalculates the comment_count value for one or more posts.

~~~
wp comment recount ...
~~~

**OPTIONS**

...
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 spam

Marks a comment as spam.

~~~
wp comment spam ...
~~~

**OPTIONS**

...
The IDs of the comments to mark as spam.

**EXAMPLES**

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

### wp comment status

Gets the status of a comment.

~~~
wp comment status
~~~

**OPTIONS**


The ID of the comment to check.

**EXAMPLES**

# Get status of comment.
$ wp comment status 1337
approved

### wp comment trash

Trashes a comment.

~~~
wp comment trash ...
~~~

**OPTIONS**

...
The IDs of the comments to trash.

**EXAMPLES**

# Trash comment.
$ wp comment trash 1337
Success: Trashed comment 1337.

### wp comment unapprove

Unapproves a comment.

~~~
wp comment unapprove ...
~~~

**OPTIONS**

...
The IDs of the comments to unapprove.

**EXAMPLES**

# Unapprove comment.
$ wp comment unapprove 1337
Success: Unapproved comment 1337.

### wp comment unspam

Unmarks a comment as spam.

~~~
wp comment unspam ...
~~~

**OPTIONS**

...
The IDs of the comments to unmark as spam.

**EXAMPLES**

# Unspam comment.
$ wp comment unspam 1337
Success: Unspammed comment 1337.

### wp comment untrash

Untrashes a comment.

~~~
wp comment untrash ...
~~~

**OPTIONS**

...
The IDs of the comments to untrash.

**EXAMPLES**

# Untrash comment.
$ wp comment untrash 1337
Success: Untrashed comment 1337.

### wp comment update

Updates one or more comments.

~~~
wp comment update ... --=
~~~

**OPTIONS**

...
One or more IDs of comments to update.

--=
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 menu

Lists, creates, assigns, and deletes the active theme's navigation menus.

~~~
wp menu
~~~

See the [Navigation Menus](https://developer.wordpress.org/themes/functionality/navigation-menus/) reference in the Theme Handbook.

**EXAMPLES**

# Create a new menu
$ wp menu create "My Menu"
Success: Created menu 200.

# List existing menus
$ wp menu list
+---------+----------+----------+-----------+-------+
| term_id | name | slug | locations | count |
+---------+----------+----------+-----------+-------+
| 200 | My Menu | my-menu | | 0 |
| 177 | Top Menu | top-menu | primary | 7 |
+---------+----------+----------+-----------+-------+

# Create a new menu link item
$ wp menu item add-custom my-menu Apple http://apple.com --porcelain
1922

# Assign the 'my-menu' menu to the 'primary' location
$ wp menu location assign my-menu primary
Success: Assigned location primary to menu my-menu.

### wp menu create

Creates a new menu.

~~~
wp menu create [--porcelain]
~~~

**OPTIONS**


A descriptive name for the menu.

[--porcelain]
Output just the new menu id.

**EXAMPLES**

$ wp menu create "My Menu"
Success: Created menu 200.

### wp menu delete

Deletes one or more menus.

~~~
wp menu delete ...
~~~

**OPTIONS**

...
The name, slug, or term ID for the menu(s).

**EXAMPLES**

$ wp menu delete "My Menu"
Deleted menu 'My Menu'.
Success: Deleted 1 of 1 menus.

### wp menu item

List, add, and delete items associated with a menu.

~~~
wp menu item
~~~

**EXAMPLES**

# Add an existing post to an existing menu
$ wp menu item add-post sidebar-menu 33 --title="Custom Test Post"
Success: Menu item added.

# Create a new menu link item
$ wp menu item add-custom sidebar-menu Apple http://apple.com
Success: Menu item added.

# Delete menu item
$ wp menu item delete 45
Success: Deleted 1 of 1 menu items.

### wp menu item add-custom

Adds a custom menu item.

~~~
wp menu item add-custom [--description=] [--attr-title=] [--target=] [--classes=] [--position=] [--parent-id=] [--porcelain]
~~~

**OPTIONS**


The name, slug, or term ID for the menu.


Title for the link.


Target URL for the link.

[--description=]
Set a custom description for the menu item.

[--attr-title=]
Set a custom title attribute for the menu item.

[--target=]
Set a custom link target for the menu item.

[--classes=]
Set a custom link classes for the menu item.

[--position=]
Specify the position of this menu item.

[--parent-id=]
Make this menu item a child of another menu item.

[--porcelain]
Output just the new menu item id.

**EXAMPLES**

$ wp menu item add-custom sidebar-menu Apple http://apple.com
Success: Menu item added.

### wp menu item add-post

Adds a post as a menu item.

~~~
wp menu item add-post [--title=] [--link=] [--description=] [--attr-title=] [--target=] [--classes=] [--position=] [--parent-id=] [--porcelain]
~~~

**OPTIONS**


The name, slug, or term ID for the menu.


Post ID to add to the menu.

[--title=]
Set a custom title for the menu item.

[--link=]
Set a custom url for the menu item.

[--description=]
Set a custom description for the menu item.

[--attr-title=]
Set a custom title attribute for the menu item.

[--target=]
Set a custom link target for the menu item.

[--classes=]
Set a custom link classes for the menu item.

[--position=]
Specify the position of this menu item.

[--parent-id=]
Make this menu item a child of another menu item.

[--porcelain]
Output just the new menu item id.

**EXAMPLES**

$ wp menu item add-post sidebar-menu 33 --title="Custom Test Post"
Success: Menu item added.

### wp menu item add-term

Adds a taxonomy term as a menu item.

~~~
wp menu item add-term [--title=] [--link=] [--description=] [--attr-title=] [--target=] [--classes=] [--position=] [--parent-id=] [--porcelain]
~~~

**OPTIONS**


The name, slug, or term ID for the menu.


Taxonomy of the term to be added.


Term ID of the term to be added.

[--title=]
Set a custom title for the menu item.

[--link=]
Set a custom url for the menu item.

[--description=]
Set a custom description for the menu item.

[--attr-title=]
Set a custom title attribute for the menu item.

[--target=]
Set a custom link target for the menu item.

[--classes=]
Set a custom link classes for the menu item.

[--position=]
Specify the position of this menu item.

[--parent-id=]
Make this menu item a child of another menu item.

[--porcelain]
Output just the new menu item id.

**EXAMPLES**

$ wp menu item add-term sidebar-menu post_tag 24
Success: Menu item added.

### wp menu item delete

Deletes one or more items from a menu.

~~~
wp menu item delete ...
~~~

**OPTIONS**

...
Database ID for the menu item(s).

**EXAMPLES**

$ wp menu item delete 45
Success: Deleted 1 of 1 menu items.

### wp menu item list

Gets a list of items associated with a menu.

~~~
wp menu item list [--fields=] [--format=]
~~~

**OPTIONS**


The name, slug, or term ID for the menu.

[--fields=]
Limit the output to specific object fields.

[--format=]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- count
- ids
- yaml
---

**AVAILABLE FIELDS**

These fields will be displayed by default for each menu item:

* db_id
* type
* title
* link
* position

These fields are optionally available:

* menu_item_parent
* object_id
* object
* type
* type_label
* target
* attr_title
* description
* classes
* xfn

**EXAMPLES**

$ wp menu item list main-menu
+-------+-----------+-------------+---------------------------------+----------+
| db_id | type | title | link | position |
+-------+-----------+-------------+---------------------------------+----------+
| 5 | custom | Home | http://example.com | 1 |
| 6 | post_type | Sample Page | http://example.com/sample-page/ | 2 |
+-------+-----------+-------------+---------------------------------+----------+

### wp menu item update

Updates a menu item.

~~~
wp menu item update [--title=] [--link=] [--description=] [--attr-title=] [--target=] [--classes=] [--position=] [--parent-id=]
~~~

**OPTIONS**


Database ID for the menu item.

[--title=]
Set a custom title for the menu item.

[--link=]
Set a custom url for the menu item.

[--description=]
Set a custom description for the menu item.

[--attr-title=]
Set a custom title attribute for the menu item.

[--target=]
Set a custom link target for the menu item.

[--classes=]
Set a custom link classes for the menu item.

[--position=]
Specify the position of this menu item.

[--parent-id=]
Make this menu item a child of another menu item.

**EXAMPLES**

$ wp menu item update 45 --title=WordPress --link='http://wordpress.org' --target=_blank --position=2
Success: Menu item updated.

### wp menu list

Gets a list of menus.

~~~
wp menu list [--fields=] [--format=]
~~~

**OPTIONS**

[--fields=]
Limit the output to specific object fields.

[--format=]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- count
- ids
- yaml
---

**AVAILABLE FIELDS**

These fields will be displayed by default for each menu:

* term_id
* name
* slug
* count

These fields are optionally available:

* term_group
* term_taxonomy_id
* taxonomy
* description
* parent
* locations

**EXAMPLES**

$ wp menu list
+---------+----------+----------+-----------+-------+
| term_id | name | slug | locations | count |
+---------+----------+----------+-----------+-------+
| 200 | My Menu | my-menu | | 0 |
| 177 | Top Menu | top-menu | primary | 7 |
+---------+----------+----------+-----------+-------+

### wp menu location

Assigns, removes, and lists a menu's locations.

~~~
wp menu location
~~~

**EXAMPLES**

# List available menu locations
$ wp menu location list
+----------+-------------------+
| location | description |
+----------+-------------------+
| primary | Primary Menu |
| social | Social Links Menu |
+----------+-------------------+

# Assign the 'primary-menu' menu to the 'primary' location
$ wp menu location assign primary-menu primary
Success: Assigned location primary to menu primary-menu.

# Remove the 'primary-menu' menu from the 'primary' location
$ wp menu location remove primary-menu primary
Success: Removed location from menu.

### wp menu location assign

Assigns a location to a menu.

~~~
wp menu location assign
~~~

**OPTIONS**


The name, slug, or term ID for the menu.


Location's slug.

**EXAMPLES**

$ wp menu location assign primary-menu primary
Success: Assigned location primary to menu primary-menu.

### wp menu location list

Lists locations for the current theme.

~~~
wp menu location list [--format=]
~~~

**OPTIONS**

[--format=]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- count
- yaml
- ids
---

**AVAILABLE FIELDS**

These fields will be displayed by default for each location:

* name
* description

**EXAMPLES**

$ wp menu location list
+----------+-------------------+
| location | description |
+----------+-------------------+
| primary | Primary Menu |
| social | Social Links Menu |
+----------+-------------------+

### wp menu location remove

Removes a location from a menu.

~~~
wp menu location remove
~~~

**OPTIONS**


The name, slug, or term ID for the menu.


Location's slug.

**EXAMPLES**

$ wp menu location remove primary-menu primary
Success: Removed location from menu.

### wp network meta

Gets, adds, updates, deletes, and lists network custom fields.

~~~
wp network meta
~~~

**EXAMPLES**

# Get a list of super-admins
$ wp network meta get 1 site_admins
array (
0 => 'supervisor',
)

### wp network meta add

Add a meta field.

~~~
wp network meta add [] [--format=]
~~~

**OPTIONS**


The ID of the object.


The name of the meta field to create.

[]
The value of the meta field. If omitted, the value is read from STDIN.

[--format=]
The serialization format for the value.
---
default: plaintext
options:
- plaintext
- json
---

### wp network meta delete

Delete a meta field.

~~~
wp network meta delete [] [] [--all]
~~~

**OPTIONS**


The ID of the object.

[]
The name of the meta field to delete.

[]
The value to delete. If omitted, all rows with key will deleted.

[--all]
Delete all meta for the object.

### wp network meta get

Get meta field value.

~~~
wp network meta get [--format=]
~~~

**OPTIONS**


The ID of the object.


The name of the meta field to get.

[--format=]
Get value in a particular format.
---
default: var_export
options:
- var_export
- json
- yaml
---

### wp network meta list

List all metadata associated with an object.

~~~
wp network meta list [--keys=] [--fields=] [--format=] [--orderby=] [--order=] [--unserialize]
~~~

**OPTIONS**


ID for the object.

[--keys=]
Limit output to metadata of specific keys.

[--fields=]
Limit the output to specific row fields. Defaults to id,meta_key,meta_value.

[--format=]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- yaml
- count
---

[--orderby=]
Set orderby which field.
---
default: id
options:
- id
- meta_key
- meta_value
---

[--order=]
Set ascending or descending order.
---
default: asc
options:
- asc
- desc
---

[--unserialize]
Unserialize meta_value output.

### wp network meta patch

Update a nested value for a meta field.

~~~
wp network meta patch ... [] [--format=]
~~~

**OPTIONS**


Patch action to perform.
---
options:
- insert
- update
- delete
---


The ID of the object.


The name of the meta field to update.

...
The name(s) of the keys within the value to locate the value to patch.

[]
The new value. If omitted, the value is read from STDIN.

[--format=