Skip to content

Commit 41b502b

Browse files
Add note about multisite usage in wp db query docs (#251)
* Add note about multisite usage in `wp db query` docs * Update README * Fix PHPCS errors --------- Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent eea28dd commit 41b502b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,29 @@ entirely.
399399
| 2 | home | http://wordpress-develop.dev | yes |
400400
+---+------+------------------------------+-----+
401401

402+
**MULTISITE USAGE**
403+
404+
Please note that the global `--url` parameter will have no effect on this command.
405+
In order to query for data in a site other than your primary site,
406+
you will need to manually modify the table names to use the prefix that includes the site's ID.
407+
408+
For example, to get the `home` option for your second site, modify the example above like so:
409+
410+
$ wp db query 'SELECT option_value FROM wp_2_options WHERE option_name="home"' --skip-column-names
411+
+----------------------+
412+
| https://example2.com |
413+
+----------------------+
414+
415+
To confirm the ID for the site you want to query, you can use the `wp site list` command:
416+
417+
# wp site list --fields=blog_id,url
418+
+---------+-----------------------+
419+
| blog_id | url |
420+
+---------+-----------------------+
421+
| 1 | https://example1.com/ |
422+
| 2 | https://example2.com/ |
423+
+---------+-----------------------+
424+
402425

403426

404427
### wp db export

src/DB_Command.php

+23
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,29 @@ public function cli( $_, $assoc_args ) {
457457
* +---+------+------------------------------+-----+
458458
* | 2 | home | http://wordpress-develop.dev | yes |
459459
* +---+------+------------------------------+-----+
460+
*
461+
* ## MULTISITE USAGE
462+
*
463+
* Please note that the global `--url` parameter will have no effect on this command.
464+
* In order to query for data in a site other than your primary site,
465+
* you will need to manually modify the table names to use the prefix that includes the site's ID.
466+
*
467+
* For example, to get the `home` option for your second site, modify the example above like so:
468+
*
469+
* $ wp db query 'SELECT option_value FROM wp_2_options WHERE option_name="home"' --skip-column-names
470+
* +----------------------+
471+
* | https://example2.com |
472+
* +----------------------+
473+
*
474+
* To confirm the ID for the site you want to query, you can use the `wp site list` command:
475+
*
476+
* # wp site list --fields=blog_id,url
477+
* +---------+-----------------------+
478+
* | blog_id | url |
479+
* +---------+-----------------------+
480+
* | 1 | https://example1.com/ |
481+
* | 2 | https://example2.com/ |
482+
* +---------+-----------------------+
460483
*/
461484
public function query( $args, $assoc_args ) {
462485

0 commit comments

Comments
 (0)