Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about multisite usage in wp db query docs #251

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading