wp site

Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation.

Commands Description
wp site empty Empties a site of its content (posts, comments, terms, and meta).
wp site delete Deletes a site in a multisite installation.
wp site create Creates a site in a multisite installation.
wp site list Lists all sites in a multisite installation.
wp site archive Archives one or more sites.
wp site unarchive Unarchives one or more sites.
wp site activate Activates one or more sites.
wp site deactivate Deactivates one or more sites.
wp site spam Marks one or more sites as spam.
wp site unspam Removes one or more sites from spam.
wp site mature Sets one or more sites as mature.
wp site unmature Sets one or more sites as immature.
wp site set-public Sets one or more sites as public.
wp site set-private Sets one or more sites as private.
wp site meta list List all metadata associated with an object.
wp site meta get Get meta field value.
wp site meta delete Delete a meta field.
wp site meta add Add a meta field.
wp site meta update Update a meta field.
wp site meta pluck Get a nested value from a meta field.
wp site meta patch Update a nested value for a meta field.
wp site option get Gets a site option.
wp site option add Adds a site option.
wp site option list Lists site options.
wp site option update Updates a site option.
wp site option delete Deletes a site option.
wp site option pluck Gets a nested value from an option.
wp site option patch Updates a nested value in an option.
wp site switch-language Activates a given language.

Examples

# Create site
$ wp site create --slug=example
Success: Site 3 created: www.example.com/example/

# Output a simple list of site URLs
$ wp site list --field=url
http://www.example.com/
http://www.example.com/subdir/

# Delete site
$ wp site delete 123
Are you sure you want to delete the 'http://www.example.com/example' site? [y/n] y
Success: The site at 'http://www.example.com/example' was deleted.

Source code of the commands


wp site empty

Empties a site of its content (posts, comments, terms, and meta).

Truncates posts, comments, and terms tables to empty a site of its content. Doesn't affect site configuration (options) or users.

If running a persistent object cache, make sure to flush the cache after emptying the site, as the cache values will be invalid otherwise.

To also empty custom database tables, you'll need to hook into command execution:

WP_CLI::add_hook( 'after_invoke:site empty', function(){
	global $wpdb;
	foreach( array( 'p2p', 'p2pmeta' ) as $table ) {
		$table = $wpdb->$table;
		$wpdb->query( "TRUNCATE $table" );
	}
});

Usage

wp site empty [--uploads] [--yes]

You can specify global options and the following:

[--uploads]
Also delete all files in the site's uploads directory.
[--yes]
Proceed to empty the site without a confirmation prompt.

Examples

$ wp site empty
Are you sure you want to empty the site at http://www.example.com of all posts, comments, and terms? [y/n] y
Success: The site at 'http://www.example.com' was emptied.

wp site delete

Deletes a site in a multisite installation.

Usage

wp site delete [{site-id}] [--slug={slug}] [--yes] [--keep-tables]

You can specify global options and the following:

[{site-id}]
The id of the site to delete. If not provided, you must set the --slug parameter.
[--slug={slug}]
Path of the blog to be deleted. Subdomain on subdomain installs, directory on subdirectory installs.
[--yes]
Answer yes to the confirmation message.
[--keep-tables]
Delete the blog from the list, but don't drop it's tables.

Examples

$ wp site delete 123
Are you sure you want to delete the http://www.example.com/example site? [y/n] y
Success: The site at 'http://www.example.com/example' was deleted.

wp site create

Creates a site in a multisite installation.

Usage

wp site create --slug={slug} [--title={title}] [--email={email}] [--network_id={network-id}] [--private] [--porcelain]

You can specify global options and the following:

--slug={slug}
Path for the new site. Subdomain on subdomain installs, directory on subdirectory installs.
[--title={title}]
Title of the new site. Default: prettified slug.
[--email={email}]
Email for Admin user. User will be created if none exists. Assignement to Super Admin if not included.
[--network_id={network-id}]
Network to associate new site with. Defaults to current network (typically 1).
[--private]
If set, the new site will be non-public (not indexed)
[--porcelain]
If set, only the site id will be output on success.

Examples

$ wp site create --slug=example
Success: Site 3 created: http://www.example.com/example/

wp site list

Lists all sites in a multisite installation.

Usage

wp site list [--network={id}] [--{field}={value}] [--site__in={value}] [--field={field}] [--fields={fields}] [--format={format}]

You can specify global options and the following:

[--network={id}]
The network to which the sites belong.
[--{field}={value}]
Filter by one or more fields (see "Available Fields" section). However, 'url' isn't an available filter, because it's created from domain + path.
[--site__in={value}]
Only list the sites with these blog_id values (comma-separated).
[--field={field}]
Prints the value of a single field for each site.
[--fields={fields}]
Comma-separated list of fields to show.
[--format={format}]

Render output in a particular format.
Default: table
Can be:

  • table
  • csv
  • count
  • ids
  • json
  • yaml

Available fields

These fields will be displayed by default for each site:

  • blog_id
  • url
  • last_updated
  • registered

These fields are optionally available:

  • site_id
  • domain
  • path
  • public
  • archived
  • mature
  • spam
  • deleted
  • lang_id

Examples

# Output a simple list of site URLs
$ wp site list --field=url
http://www.example.com/
http://www.example.com/subdir/

wp site archive

Archives one or more sites.

Usage

wp site archive {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to archive.

Examples

$ wp site archive 123
Success: Site 123 archived.

wp site unarchive

Unarchives one or more sites.

Usage

wp site unarchive {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to unarchive.

Examples

$ wp site unarchive 123
Success: Site 123 unarchived.

wp site activate

Activates one or more sites.

Usage

wp site activate {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to activate.

Examples

$ wp site activate 123
Success: Site 123 activated.

wp site deactivate

Deactivates one or more sites.

Usage

wp site deactivate {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to deactivate.

Examples

$ wp site deactivate 123
Success: Site 123 deactivated.

wp site spam

Marks one or more sites as spam.

Usage

wp site spam {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to be marked as spam.

Examples

$ wp site spam 123
Success: Site 123 marked as spam.

wp site unspam

Removes one or more sites from spam.

Usage

wp site unspam {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to remove from spam.

Examples

$ wp site unspam 123
Success: Site 123 removed from spam.

wp site mature

Sets one or more sites as mature.

Usage

wp site mature {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to set as mature.

Examples

$ wp site mature 123
Success: Site 123 marked as mature.

wp site unmature

Sets one or more sites as immature.

Usage

wp site unmature {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to set as unmature.

Examples

$ wp site general 123
Success: Site 123 marked as unmature.

wp site set-public

Sets one or more sites as public.

Usage

wp site set-public {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to set as public.

Examples

$ wp site public 123
Success: Site 123 marked as public.

wp site set-private

Sets one or more sites as private.

Usage

wp site set-private {id}...

You can specify global options and the following:

{id}...
One or more IDs of sites to set as private.

Examples

$ wp site private 123
Success: Site 123 marked as private.

wp site meta list

List all metadata associated with an object.

Usage

wp site 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 site meta get

Get meta field value.

Usage

wp site 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 site meta delete

Delete a meta field.

Usage

wp site 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 site meta add

Add a meta field.

Usage

wp site 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 site meta update

Update a meta field.

Usage

wp site 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 site meta pluck

Get a nested value from a meta field.

Usage

wp site 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

Examples

Suppose we have such a serialised array in the socials_opt option:

[
	'location_home' => 'none',
	...
	'icons_order' => [
		[
			'twitter' => 'Twitter',
			'linkedIn' => 'LinkedIn',
			'pinterest' => 'Pinterest',
			'facebook' => 'Facebook',
			'google_plus' => 'Google Plus',
		]
	]
	...
]

Let's get the value of an individual element of a serialised array using the pluck command:

$ wp option pluck socials_opt icons_order

[
	'twitter' => 'Twitter',
	'linkedIn' => 'LinkedIn',
	'pinterest' => 'Pinterest',
	'facebook' => 'Facebook',
	'google_plus' => 'Google Plus',
]

Let's get the value of the further nested element:

$ wp option pluck socials_opt icons_order twitter

Twitter

wp site meta patch

Update a nested value for a meta field.

Usage

wp site 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

Examples

Suppose we have such a serialised array in the socials_opt option:

[
	'location_home' => 'none',
	...
	'icons_order' => [
		[
			'twitter' => 'Twitter',
			'linkedIn' => 'LinkedIn',
			'pinterest' => 'Pinterest',
			'facebook' => 'Facebook',
			'google_plus' => 'Google Plus',
		]
	]
	...
]

Let's update the value of the nested element of the serialised array from Twitter to TWITTER:

$ wp option patch update socials_opt icons_order twitter TWITTER

wp site option get

Gets a site option.

Usage

wp site option get {key} [--format={format}]

You can specify global options and the following:

{key}
Key for the site option.
[--format={format}]

Get value in a particular format.
Default: var_export
Can be:

  • var_export
  • json
  • yaml

Examples

# Get site upload filetypes
$ wp site option get upload_filetypes
jpg jpeg png gif mov avi mpg

wp site option add

Adds a site option.

Usage

wp site option add {key} [{value}] [--format={format}]

You can specify global options and the following:

{key}
The name of the site option to add.
[{value}]
The value of the site option to add. If ommited, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
Default: plaintext
Can be:

  • plaintext
  • json

Examples

# Create a site option by reading a JSON file
$ wp site option add my_option --format=json < config.json
Success: Added 'my_option' site option.

wp site option list

Lists site options.

Usage

wp site option list [--search={pattern}] [--site_id={id}] [--field={field}] [--fields={fields}] [--format={format}]

You can specify global options and the following:

[--search={pattern}]
Use wildcards ( * and ? ) to match option name.
[--site_id={id}]
Limit options to those of a particular site id.
[--field={field}]
Prints the value of a single field.
[--fields={fields}]
Limit the output to specific object fields.
[--format={format}]

The serialization format for the value. total_bytes displays the total size of matching options in bytes.
Default: table
Can be:

  • table
  • json
  • csv
  • count
  • yaml
  • total_bytes

Available fields

This field will be displayed by default for each matching option:

  • meta_key
  • meta_value

These fields are optionally available:

  • meta_id
  • site_id
  • size_bytes

Examples

# List all site options begining with "i2f_"
$ wp site option list --search="i2f_*"
+-------------+--------------+
| meta_key    | meta_value   |
+-------------+--------------+
| i2f_version | 0.1.0        |
+-------------+--------------+

wp site option update

Updates a site option.

Usage

wp site option update {key} [{value}] [--format={format}]

You can specify global options and the following:

{key}
The name of the site option to update.
[{value}]
The new value. If ommited, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
Default: plaintext
Can be:

  • plaintext
  • json

Examples

# Update a site option by reading from a file
$ wp site option update my_option < value.txt
Success: Updated 'my_option' site option.

wp site option delete

Deletes a site option.

Usage

wp site option delete {key}

You can specify global options and the following:

{key}
Key for the site option.

Examples

$ wp site option delete my_option
Success: Deleted 'my_option' site option.

wp site option pluck

Gets a nested value from an option.

Usage

wp site option pluck {key} {key-path}... [--format={format}]

You can specify global options and the following:

{key}
The option name.
{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 site option patch

Updates a nested value in an option.

Usage

wp site option patch {action} {key} {key-path}... [{value}] [--format={format}]

You can specify global options and the following:

{action}

Patch action to perform.

Can be:

  • insert
  • update
  • delete
{key}
The option name.
{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

wp site switch-language

Activates a given language.

Usage

wp site switch-language {language}

You can specify global options and the following:

{language}
Language code to activate.

Examples

$ wp site switch-language ja
Success: Language activated.