-
Notifications
You must be signed in to change notification settings - Fork 97
Query sites through WP_Site_Query in wp site list
#639
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
Merged
swissspidy
merged 7 commits into
main
from
claude/wp-cli-issue-5286-n50evd-site-list-query
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e810bc2
Query sites through WP_Site_Query in `wp site list`
claude ef5bf2a
Use WP_Date_Query for exact registration and update dates
claude 808df35
Let WP_Date_Query interpret the site list date filters
claude dea0396
Address review feedback on the date filters
claude 0458e4d
Merge remote-tracking branch 'origin/main' into claude/wp-cli-issue-5…
claude b59965b
Fold the date filter notes into their own option entries
claude b5ea101
Cover --site_user intersecting with --site__in
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1041,3 +1041,178 @@ Feature: Manage sites in a multisite installation | |
| """ | ||
| 3 | ||
| """ | ||
|
|
||
| Scenario: List sites using WP_Site_Query arguments | ||
| Given a WP multisite install | ||
|
|
||
| When I run `wp site create --slug=alpha --porcelain` | ||
| Then STDOUT should be a number | ||
| And save STDOUT as {ALPHA_ID} | ||
|
|
||
| When I run `wp site create --slug=beta --porcelain` | ||
| Then STDOUT should be a number | ||
| And save STDOUT as {BETA_ID} | ||
|
|
||
| # --search, --site__not_in, --number, --offset and --orderby all come from | ||
| # WP_Site_Query and were silently ignored before. | ||
| When I run `wp site list --search=alpha --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| When I run `wp site list --site__not_in={ALPHA_ID} --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 2 | ||
| """ | ||
|
|
||
| When I run `wp site list --number=1 --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 1 | ||
| """ | ||
|
|
||
| When I run `wp site list --number=1 --offset=1 --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| When I run `wp site list --orderby=id --order=desc --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| {BETA_ID} | ||
| {ALPHA_ID} | ||
| 1 | ||
| """ | ||
|
|
||
| Scenario: Existing site list filters keep working against WP_Site_Query | ||
| Given a WP multisite install | ||
|
|
||
| When I run `wp site create --slug=alpha --porcelain` | ||
| Then STDOUT should be a number | ||
| And save STDOUT as {ALPHA_ID} | ||
|
|
||
| When I run `wp site create --slug=beta --porcelain` | ||
| Then STDOUT should be a number | ||
| And save STDOUT as {BETA_ID} | ||
|
|
||
| # --site__in returns rows in the order the IDs were given. | ||
| When I run `wp site list --site__in={BETA_ID},{ALPHA_ID} --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| {BETA_ID} | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| When I run `wp site list --blog_id={ALPHA_ID} --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| When I run `wp site list --site_id=1 --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 3 | ||
| """ | ||
|
|
||
| When I run `wp site list --site_id=2 --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 0 | ||
| """ | ||
|
|
||
| When I run `wp site list --site-path=/alpha/ --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| # admin belongs to every site, bobby only to the one they were created on, so the | ||
| # two counts differ and neither can pass by accident. | ||
| When I run `wp site list --site_user=admin --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 3 | ||
| """ | ||
|
|
||
| When I run `wp user create bobby [email protected] --role=author --porcelain` | ||
| Then STDOUT should be a number | ||
|
|
||
| When I run `wp site list --site_user=bobby --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| 1 | ||
| """ | ||
|
|
||
| # --site__in and --site_user narrow each other rather than one replacing the | ||
| # other, so the pair keeps only the sites satisfying both. | ||
| When I run `wp site list --site__in={ALPHA_ID} --site_user=bobby --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 0 | ||
| """ | ||
|
|
||
| When I run `wp site list --site__in=1,{ALPHA_ID} --site_user=bobby --field=blog_id` | ||
| Then STDOUT should be: | ||
| """ | ||
| 1 | ||
| """ | ||
|
|
||
| Scenario: Filter the site list by registration or update date | ||
| Given a WP multisite install | ||
|
|
||
| When I run `wp site create --slug=alpha --porcelain` | ||
| Then STDOUT should be a number | ||
| And save STDOUT as {ALPHA_ID} | ||
|
|
||
| When I run `wp site list --blog_id={ALPHA_ID} --field=registered` | ||
| Then STDOUT should not be empty | ||
| And save STDOUT as {REGISTERED} | ||
| And save STDOUT '(\d{4}-\d{2}-\d{2})' as {REGISTERED_DAY} | ||
|
|
||
| When I run `wp site list --registered='{REGISTERED}' --field=blog_id` | ||
| Then STDOUT should contain: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| # A value carrying no time of day matches every site registered that day, and | ||
| # only those - a day nothing was registered on comes back empty. | ||
| When I run `wp site list --registered={REGISTERED_DAY} --field=blog_id` | ||
| Then STDOUT should contain: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| When I run `wp site list --registered=1999-01-01 --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 0 | ||
| """ | ||
|
|
||
| When I run `wp site list --registered='1999-01-01 00:00:00' --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 0 | ||
| """ | ||
|
|
||
| When I run `wp site list --blog_id={ALPHA_ID} --field=last_updated` | ||
| Then STDOUT should not be empty | ||
| And save STDOUT as {LAST_UPDATED} | ||
|
|
||
| When I run `wp site list --last_updated='{LAST_UPDATED}' --field=blog_id` | ||
| Then STDOUT should contain: | ||
| """ | ||
| {ALPHA_ID} | ||
| """ | ||
|
|
||
| # Interpreting the value is left to WP_Date_Query, which resolves anything it | ||
| # cannot parse to a date no site can have registered on. | ||
| When I run `wp site list --registered=notadate --format=count` | ||
| Then STDOUT should be: | ||
| """ | ||
| 0 | ||
| """ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.