Skip to content

Commit 8ff4d0c

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/wp-cli-issue-5286-n50evd-silent-noop
# Conflicts: # features/post.feature
2 parents d93ac5c + 240b603 commit 8ff4d0c

5 files changed

Lines changed: 674 additions & 26 deletions

File tree

‎README.md‎

Lines changed: 167 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,7 +3150,7 @@ wp post get <id> [--field=<field>] [--fields=<fields>] [--format=<format>]
31503150
Gets a list of posts.
31513151

31523152
~~~
3153-
wp post list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
3153+
wp post list [--<field>=<value>] [--p=<id>|ID] [--title=<title>|post_title] [--name=<slug>|post_name] [--author=<author>|post_author] [--author_name=<author_name>] [--post_type=<post_type>] [--post_status=<post_status>] [--post_parent=<post_parent>] [--post_mime_type=<post_mime_type>] [--menu_order=<menu_order>] [--comment_status=<comment_status>] [--ping_status=<ping_status>] [--comment_count=<comment_count>] [--s=<string>] [--year=<year>] [--monthnum=<monthnum>] [--day=<day>] [--m=<yearmonth>] [--w=<week>] [--field=<field>] [--fields=<fields>] [--format=<format>]
31543154
~~~
31553155

31563156
Display posts based on all arguments supported by [WP_Query()](https://developer.wordpress.org/reference/classes/wp_query/).
@@ -3159,7 +3159,77 @@ Only shows post types marked as post by default.
31593159
**OPTIONS**
31603160

31613161
[--<field>=<value>]
3162-
One or more args to pass to WP_Query.
3162+
One or more args to pass to WP_Query. The arguments below are the ones
3163+
that filter on what this command displays; anything else WP_Query accepts
3164+
still works and is documented with WP_Query itself.
3165+
3166+
[--p=<id>|ID]
3167+
Filter by post ID. `--ID` is the name of the column this filters and is
3168+
accepted as an alias.
3169+
3170+
[--title=<title>|post_title]
3171+
Filter by post title, matched in full. `--post_title` is the name of the
3172+
column this filters and is accepted as an alias.
3173+
3174+
[--name=<slug>|post_name]
3175+
Filter by post slug. `--post_name` is the name of the column this filters
3176+
and is accepted as an alias.
3177+
Note: this makes the query a single-post one, and WP_Query returns a draft
3178+
from one of those only to a user who can edit it. WP-CLI runs as no user
3179+
unless the global `--user` argument says otherwise, so pass that to filter
3180+
drafts by slug.
3181+
3182+
[--author=<author>|post_author]
3183+
Filter by the ID of the post's author. `--post_author` is the name of the
3184+
column this filters and is accepted as an alias.
3185+
3186+
[--author_name=<author_name>]
3187+
Filter by the 'user_nicename' of the post's author.
3188+
3189+
[--post_type=<post_type>]
3190+
Filter by post type. Defaults to 'post'. Accepts a comma-separated list,
3191+
or 'any' for every type registered without 'exclude_from_search'.
3192+
3193+
[--post_status=<post_status>]
3194+
Filter by post status. Defaults to 'any', which is every status
3195+
registered without 'exclude_from_search' - so trashed and auto-draft posts
3196+
are left out until asked for by name, e.g. `--post_status=trash`.
3197+
3198+
[--post_parent=<post_parent>]
3199+
Filter by the ID of the parent post.
3200+
3201+
[--post_mime_type=<post_mime_type>]
3202+
Filter by MIME type. Only attachments carry one.
3203+
3204+
[--menu_order=<menu_order>]
3205+
Filter by menu order.
3206+
3207+
[--comment_status=<comment_status>]
3208+
Filter by comment status. Accepts 'open' or 'closed'.
3209+
3210+
[--ping_status=<ping_status>]
3211+
Filter by ping status. Accepts 'open' or 'closed'.
3212+
3213+
[--comment_count=<comment_count>]
3214+
Filter by number of comments.
3215+
3216+
[--s=<string>]
3217+
Only list the posts matching this search term.
3218+
3219+
[--year=<year>]
3220+
Filter by four-digit year, e.g. 2024.
3221+
3222+
[--monthnum=<monthnum>]
3223+
Filter by month number, 1 to 12.
3224+
3225+
[--day=<day>]
3226+
Filter by day of the month, 1 to 31.
3227+
3228+
[--m=<yearmonth>]
3229+
Filter by year and month together, e.g. 202401.
3230+
3231+
[--w=<week>]
3232+
Filter by week of the year, 0 to 53.
31633233

31643234
[--field=<field>]
31653235
Prints the value of a single field for each post.
@@ -5443,41 +5513,60 @@ These fields are optionally available:
54435513
Lists all sites in a multisite installation.
54445514

54455515
~~~
5446-
wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_user=<value>] [--site-path=<path>] [--blog_id=<blog_id>] [--site_id=<site_id>] [--domain=<domain>] [--registered=<date>] [--last_updated=<date>] [--public=<public>] [--archived=<archived>] [--mature=<mature>] [--spam=<spam>] [--deleted=<deleted>] [--lang_id=<lang_id>] [--field=<field>] [--fields=<fields>] [--format=<format>]
5516+
wp site list [--network=<id>|site_id|network_id] [--<field>=<value>] [--site__in=<value>] [--site__not_in=<value>] [--site_user=<value>] [--site-path=<path>] [--path__in=<value>] [--path__not_in=<value>] [--blog_id=<blog_id>|ID] [--network__in=<value>] [--network__not_in=<value>] [--domain=<domain>] [--domain__in=<value>] [--domain__not_in=<value>] [--registered=<date>] [--last_updated=<date>] [--public=<public>] [--archived=<archived>] [--mature=<mature>] [--spam=<spam>] [--deleted=<deleted>] [--lang_id=<lang_id>] [--lang__in=<value>] [--lang__not_in=<value>] [--search=<string>] [--search_columns=<columns>] [--meta_key=<meta_key>] [--meta_value=<meta_value>] [--meta_compare=<meta_compare>] [--meta_type=<meta_type>] [--meta_query=<meta_query>] [--date_query=<date_query>] [--number=<number>] [--offset=<offset>] [--no_found_rows=<no_found_rows>] [--update_site_cache=<update_site_cache>] [--update_site_meta_cache=<update_site_meta_cache>] [--orderby=<field>] [--order=<order>] [--field=<field>] [--fields=<fields>] [--format=<format>]
54475517
~~~
54485518

54495519
**OPTIONS**
54505520

5451-
[--network=<id>]
5452-
The network to which the sites belong.
5521+
[--network=<id>|site_id|network_id]
5522+
The network to which the sites belong. `--site_id` is the name of the
5523+
column this filters, `--network_id` is WP_Site_Query's name for it, and
5524+
both are accepted as aliases. `--network` wins when more than one is given.
54535525

54545526
[--<field>=<value>]
54555527
Filter by one or more fields (see "Available Fields" section), or pass any
5456-
other argument accepted by WP_Site_Query, such as 'search', 'site__not_in',
5457-
'number', 'offset', 'orderby' or 'order'. However, 'url' isn't an available
5528+
other argument accepted by WP_Site_Query. However, 'url' isn't an available
54585529
filter, as it comes from 'home' in wp_options.
54595530
Note: '--path' conflicts with the global parameter of the same name; use
54605531
'--site-path' to filter by path instead.
54615532

54625533
[--site__in=<value>]
54635534
Only list the sites with these blog_id values (comma-separated).
54645535

5536+
[--site__not_in=<value>]
5537+
Exclude the sites with these blog_id values (comma-separated).
5538+
54655539
[--site_user=<value>]
54665540
Only list the sites with this user.
54675541

54685542
[--site-path=<path>]
54695543
Filter by path. Avoids conflict with the global `--path` parameter.
54705544

5471-
[--blog_id=<blog_id>]
5472-
Filter by site ID.
5545+
[--path__in=<value>]
5546+
Only list the sites with these paths (comma-separated).
54735547

5474-
[--site_id=<site_id>]
5475-
Filter by the ID of the network the site belongs to. `--network` is an
5476-
alias for this, and takes precedence when both are given.
5548+
[--path__not_in=<value>]
5549+
Exclude the sites with these paths (comma-separated).
5550+
5551+
[--blog_id=<blog_id>|ID]
5552+
Filter by site ID. `--ID` is WP_Site_Query's name for the same filter
5553+
and is accepted as an alias.
5554+
5555+
[--network__in=<value>]
5556+
Only list the sites belonging to these network IDs (comma-separated).
5557+
5558+
[--network__not_in=<value>]
5559+
Exclude the sites belonging to these network IDs (comma-separated).
54775560

54785561
[--domain=<domain>]
54795562
Filter by domain.
54805563

5564+
[--domain__in=<value>]
5565+
Only list the sites with these domains (comma-separated).
5566+
5567+
[--domain__not_in=<value>]
5568+
Exclude the sites with these domains (comma-separated).
5569+
54815570
[--registered=<date>]
54825571
Filter by the date the site was registered. Accepts a timestamp or a
54835572
date; a value carrying no time of day matches that whole day.
@@ -5504,6 +5593,72 @@ wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_u
55045593
[--lang_id=<lang_id>]
55055594
Filter by language ID.
55065595

5596+
[--lang__in=<value>]
5597+
Only list the sites with these language IDs (comma-separated).
5598+
5599+
[--lang__not_in=<value>]
5600+
Exclude the sites with these language IDs (comma-separated).
5601+
5602+
[--search=<string>]
5603+
Only list the sites matching this search term. Searches the domain and
5604+
path columns unless `--search_columns` narrows it.
5605+
5606+
[--search_columns=<columns>]
5607+
Comma-separated list of columns `--search` looks in. Accepts 'domain'
5608+
and 'path'.
5609+
5610+
[--meta_key=<meta_key>]
5611+
Filter by this site meta key. The site meta arguments need WordPress 5.1
5612+
or later, which is where multisite gained the table they read.
5613+
5614+
[--meta_value=<meta_value>]
5615+
Filter by this site meta value. Used together with `--meta_key`.
5616+
5617+
[--meta_compare=<meta_compare>]
5618+
Operator to test the meta value against. Accepts the operators
5619+
WP_Meta_Query supports, such as '=', '!=', 'LIKE' or 'IN'.
5620+
5621+
[--meta_type=<meta_type>]
5622+
Cast the meta value to this type, such as 'NUMERIC' or 'DATE'.
5623+
5624+
[--meta_query=<meta_query>]
5625+
A WP_Meta_Query clause list, as JSON, for conditions the meta_* arguments
5626+
above cannot express.
5627+
5628+
[--date_query=<date_query>]
5629+
A WP_Date_Query clause list, as JSON, for ranges `--registered` and
5630+
`--last_updated` cannot express. Giving those as well narrows this further
5631+
rather than replacing it.
5632+
5633+
[--number=<number>]
5634+
Limit the number of sites returned.
5635+
5636+
[--offset=<offset>]
5637+
Number of sites to skip. Used together with `--number`.
5638+
5639+
[--no_found_rows=<no_found_rows>]
5640+
Whether to skip counting the total rows the query matches. Accepts 1 or 0.
5641+
5642+
[--update_site_cache=<update_site_cache>]
5643+
Whether to prime the object cache with the sites found. Accepts 1 or 0.
5644+
Turning it off saves work when listing a large network once.
5645+
5646+
[--update_site_meta_cache=<update_site_meta_cache>]
5647+
Whether to prime the object cache with the site meta of the sites found.
5648+
Accepts 1 or 0.
5649+
5650+
[--orderby=<field>]
5651+
Order the results by this field, such as 'blog_id', 'domain', 'path',
5652+
'registered', 'last_updated' or 'site__in'.
5653+
5654+
[--order=<order>]
5655+
Whether to order the results ascending or descending.
5656+
---
5657+
options:
5658+
- asc
5659+
- desc
5660+
---
5661+
55075662
[--field=<field>]
55085663
Prints the value of a single field for each site.
55095664

‎features/post.feature‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,103 @@ Feature: Manage WordPress posts
592592
{"block_version":1}
593593
"""
594594

595+
Scenario: Filtering by the wp_posts column names
596+
When I run `wp post create --post_title='Alpha' --post_status=publish --porcelain`
597+
Then STDOUT should be a number
598+
599+
# 'title', 'name' and 'author' are WP_Query's names for these filters. The
600+
# columns they filter on are spelled differently, and passing the column
601+
# name used to reach WP_Query as an argument it does not know: it was
602+
# dropped, and every post came back. They are aliases now.
603+
When I run `wp post list --title='Hello world!' --format=count`
604+
Then STDOUT should be:
605+
"""
606+
1
607+
"""
608+
609+
When I run `wp post list --post_title='Hello world!' --format=count`
610+
Then STDOUT should be:
611+
"""
612+
1
613+
"""
614+
615+
When I run `wp post list --name=alpha --format=count`
616+
Then STDOUT should be:
617+
"""
618+
1
619+
"""
620+
621+
When I run `wp post list --post_name=alpha --format=count`
622+
Then STDOUT should be:
623+
"""
624+
1
625+
"""
626+
627+
# Only the bundled post matches: a post created by WP-CLI has author 0,
628+
# because WP-CLI runs as no user unless told otherwise.
629+
When I run `wp post list --author=1 --format=count`
630+
Then STDOUT should be:
631+
"""
632+
1
633+
"""
634+
635+
When I run `wp post list --post_author=1 --format=count`
636+
Then STDOUT should be:
637+
"""
638+
1
639+
"""
640+
641+
When I run `wp post list --p=1 --format=count`
642+
Then STDOUT should be:
643+
"""
644+
1
645+
"""
646+
647+
When I run `wp post list --ID=1 --format=count`
648+
Then STDOUT should be:
649+
"""
650+
1
651+
"""
652+
653+
Scenario: Filtering drafts by slug needs a user
654+
When I run `wp post create --post_title='Beta' --post_name=beta --post_status=draft --porcelain`
655+
Then STDOUT should be a number
656+
657+
# '--name' makes this a single-post query, and WP_Query hands a draft from
658+
# one of those only to a user who can edit it. WP-CLI is no user by default.
659+
When I run `wp post list --name=beta --field=ID`
660+
Then STDOUT should be empty
661+
662+
# The global '--user' argument is what makes it reachable.
663+
When I run `wp post list --name=beta --user=1 --field=ID`
664+
Then STDOUT should not be empty
665+
666+
Scenario: Trashed posts need their status named
667+
When I run `wp post create --post_title='Doomed' --post_status=publish --porcelain`
668+
Then STDOUT should be a number
669+
And save STDOUT as {DOOMED_ID}
670+
671+
When I run `wp post delete {DOOMED_ID}`
672+
Then STDOUT should contain:
673+
"""
674+
Success: Trashed post
675+
"""
676+
677+
# This command defaults post_status to 'any', and WP_Query reads 'any' as
678+
# every status registered without 'exclude_from_search' - which leaves out
679+
# 'trash' and 'auto-draft'.
680+
When I run `wp post list --field=ID`
681+
Then STDOUT should not contain:
682+
"""
683+
{DOOMED_ID}
684+
"""
685+
686+
When I run `wp post list --post_status=trash --field=ID`
687+
Then STDOUT should contain:
688+
"""
689+
{DOOMED_ID}
690+
"""
691+
595692
Scenario: Set a post's modification date on update
596693
Given a WP install
597694

0 commit comments

Comments
 (0)