Skip to content

Commit

Permalink
Add note about multisite usage in wp db query docs (#251)
Browse files Browse the repository at this point in the history
* Add note about multisite usage in `wp db query` docs

* Update README

* Fix PHPCS errors

---------

Co-authored-by: Daniel Bachhuber <[email protected]>
  • Loading branch information
Scotchester and danielbachhuber authored Apr 12, 2024
1 parent eea28dd commit 41b502b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,29 @@ entirely.
| 2 | home | http://wordpress-develop.dev | yes |
+---+------+------------------------------+-----+

**MULTISITE USAGE**

Please note that the global `--url` parameter will have no effect on this command.
In order to query for data in a site other than your primary site,
you will need to manually modify the table names to use the prefix that includes the site's ID.

For example, to get the `home` option for your second site, modify the example above like so:

$ wp db query 'SELECT option_value FROM wp_2_options WHERE option_name="home"' --skip-column-names
+----------------------+
| https://example2.com |
+----------------------+

To confirm the ID for the site you want to query, you can use the `wp site list` command:

# wp site list --fields=blog_id,url
+---------+-----------------------+
| blog_id | url |
+---------+-----------------------+
| 1 | https://example1.com/ |
| 2 | https://example2.com/ |
+---------+-----------------------+



### wp db export
Expand Down
23 changes: 23 additions & 0 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,29 @@ public function cli( $_, $assoc_args ) {
* +---+------+------------------------------+-----+
* | 2 | home | http://wordpress-develop.dev | yes |
* +---+------+------------------------------+-----+
*
* ## MULTISITE USAGE
*
* Please note that the global `--url` parameter will have no effect on this command.
* In order to query for data in a site other than your primary site,
* you will need to manually modify the table names to use the prefix that includes the site's ID.
*
* For example, to get the `home` option for your second site, modify the example above like so:
*
* $ wp db query 'SELECT option_value FROM wp_2_options WHERE option_name="home"' --skip-column-names
* +----------------------+
* | https://example2.com |
* +----------------------+
*
* To confirm the ID for the site you want to query, you can use the `wp site list` command:
*
* # wp site list --fields=blog_id,url
* +---------+-----------------------+
* | blog_id | url |
* +---------+-----------------------+
* | 1 | https://example1.com/ |
* | 2 | https://example2.com/ |
* +---------+-----------------------+
*/
public function query( $args, $assoc_args ) {

Expand Down

0 comments on commit 41b502b

Please sign in to comment.