Skip to content

Commit 81f5b3e

Browse files
committed
Document the meta, time, password and ordering arguments too
Sweeping the rest of WP_Query's query vars turned up more that work here and nothing writes down. Each was tried with a value shaped the way the command line delivers it, and only the ones that changed the result are documented: - meta_key and meta_value, which is how you filter on a custom field - hour, minute and second, which finish the date family that already had year, monthnum, day, m and w - has_password and post_password - orderby and order Left alone for cause: 'sentence', 'perm', 'preview', 'error', 'tb', 'paged', 'embed' and 'sticky' change nothing when passed, and 'page_id' filters but sits within two edits of 'paged' and 'tag_id', so documenting it would add two false positives to wp-cli/wp-cli#6392 the way 'tag_id' would. All three of hour, minute and second together is deliberately not asserted. That path compares a DATE_FORMAT() string rather than separate HOUR() and MINUTE() clauses, and the SQLite integration plugin does not emulate it the way MySQL does: the same query matches on MariaDB and matches nothing on SQLite. Two units at a time behaves the same on both and is covered. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
1 parent 37bcf2a commit 81f5b3e

3 files changed

Lines changed: 132 additions & 1 deletion

File tree

README.md

Lines changed: 32 additions & 1 deletion
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>] [--p=<id>|ID] [--title=<title>|post_title] [--name=<slug>|post_name] [--author=<author>|post_author] [--author_name=<author_name>] [--cat=<cat>] [--category_name=<category_name>] [--tag=<tag>] [--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>]
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>] [--cat=<cat>] [--category_name=<category_name>] [--tag=<tag>] [--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>] [--hour=<hour>] [--minute=<minute>] [--second=<second>] [--m=<yearmonth>] [--w=<week>] [--meta_key=<meta_key>] [--meta_value=<meta_value>] [--has_password=<has_password>] [--post_password=<post_password>] [--orderby=<orderby>] [--order=<order>] [--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/).
@@ -3236,12 +3236,43 @@ Only shows post types marked as post by default.
32363236
[--day=<day>]
32373237
Filter by day of the month, 1 to 31.
32383238

3239+
[--hour=<hour>]
3240+
Filter by hour, 0 to 23.
3241+
3242+
[--minute=<minute>]
3243+
Filter by minute, 0 to 59.
3244+
3245+
[--second=<second>]
3246+
Filter by second, 0 to 59.
3247+
32393248
[--m=<yearmonth>]
32403249
Filter by year and month together, e.g. 202401.
32413250

32423251
[--w=<week>]
32433252
Filter by week of the year, 0 to 53.
32443253

3254+
[--meta_key=<meta_key>]
3255+
Filter by posts having this meta key. Pair it with `--meta_value` to
3256+
filter on the value as well.
3257+
3258+
[--meta_value=<meta_value>]
3259+
Filter by this meta value. Needs `--meta_key` to say which key it
3260+
belongs to.
3261+
3262+
[--has_password=<has_password>]
3263+
Filter by whether the post has a password. Accepts 1 or 0.
3264+
3265+
[--post_password=<post_password>]
3266+
Filter by the post's password, matched in full.
3267+
3268+
[--orderby=<orderby>]
3269+
Order the results by this field. Accepts what WP_Query accepts, e.g.
3270+
'date', 'title', 'ID', 'menu_order', 'rand', or 'meta_value' alongside
3271+
`--meta_key`.
3272+
3273+
[--order=<order>]
3274+
Direction to order by. Accepts 'ASC' or 'DESC'.
3275+
32453276
[--field=<field>]
32463277
Prints the value of a single field for each post.
32473278

features/post.feature

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,72 @@ Feature: Manage WordPress posts
723723
"""
724724
1
725725
"""
726+
727+
Scenario: Filtering by meta, time of day, password and order
728+
When I run `wp post create --post_title='Timed' --post_status=publish --post_date='2020-03-04 05:06:07' --porcelain`
729+
Then STDOUT should be a number
730+
And save STDOUT as {TIMED_ID}
731+
732+
When I run `wp post meta add {TIMED_ID} color blue`
733+
Then STDOUT should not be empty
734+
735+
When I run `wp post create --post_title='Locked' --post_status=publish --post_password=secret --porcelain`
736+
Then STDOUT should be a number
737+
738+
# Time of day, alongside the year/month/day filters already documented.
739+
# Two units at once exercises the combined path; all three of hour, minute
740+
# and second together is left out on purpose, because that path compares a
741+
# DATE_FORMAT() string and the SQLite integration plugin does not emulate
742+
# it the way MySQL does, so it matches nothing there.
743+
When I run `wp post list --hour=5 --minute=6 --field=post_title`
744+
Then STDOUT should be:
745+
"""
746+
Timed
747+
"""
748+
749+
When I run `wp post list --second=7 --field=post_title`
750+
Then STDOUT should be:
751+
"""
752+
Timed
753+
"""
754+
755+
# A meta key on its own, then narrowed by its value.
756+
When I run `wp post list --meta_key=color --field=post_title`
757+
Then STDOUT should be:
758+
"""
759+
Timed
760+
"""
761+
762+
When I run `wp post list --meta_key=color --meta_value=red --format=count`
763+
Then STDOUT should be:
764+
"""
765+
0
766+
"""
767+
768+
When I run `wp post list --has_password=1 --field=post_title`
769+
Then STDOUT should be:
770+
"""
771+
Locked
772+
"""
773+
774+
When I run `wp post list --post_password=secret --field=post_title`
775+
Then STDOUT should be:
776+
"""
777+
Locked
778+
"""
779+
780+
When I run `wp post list --orderby=title --order=ASC --field=post_title`
781+
Then STDOUT should be:
782+
"""
783+
Hello world!
784+
Locked
785+
Timed
786+
"""
787+
788+
When I run `wp post list --orderby=title --order=DESC --field=post_title`
789+
Then STDOUT should be:
790+
"""
791+
Timed
792+
Locked
793+
Hello world!
794+
"""

src/Post_Command.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,43 @@ protected function delete_callback( $post_id, $assoc_args ) {
694694
* [--day=<day>]
695695
* : Filter by day of the month, 1 to 31.
696696
*
697+
* [--hour=<hour>]
698+
* : Filter by hour, 0 to 23.
699+
*
700+
* [--minute=<minute>]
701+
* : Filter by minute, 0 to 59.
702+
*
703+
* [--second=<second>]
704+
* : Filter by second, 0 to 59.
705+
*
697706
* [--m=<yearmonth>]
698707
* : Filter by year and month together, e.g. 202401.
699708
*
700709
* [--w=<week>]
701710
* : Filter by week of the year, 0 to 53.
702711
*
712+
* [--meta_key=<meta_key>]
713+
* : Filter by posts having this meta key. Pair it with `--meta_value` to
714+
* filter on the value as well.
715+
*
716+
* [--meta_value=<meta_value>]
717+
* : Filter by this meta value. Needs `--meta_key` to say which key it
718+
* belongs to.
719+
*
720+
* [--has_password=<has_password>]
721+
* : Filter by whether the post has a password. Accepts 1 or 0.
722+
*
723+
* [--post_password=<post_password>]
724+
* : Filter by the post's password, matched in full.
725+
*
726+
* [--orderby=<orderby>]
727+
* : Order the results by this field. Accepts what WP_Query accepts, e.g.
728+
* 'date', 'title', 'ID', 'menu_order', 'rand', or 'meta_value' alongside
729+
* `--meta_key`.
730+
*
731+
* [--order=<order>]
732+
* : Direction to order by. Accepts 'ASC' or 'DESC'.
733+
*
703734
* [--field=<field>]
704735
* : Prints the value of a single field for each post.
705736
*

0 commit comments

Comments
 (0)