Skip to content

Commit f349e8f

Browse files
authored
wp post list: Add JSON input support for tax_query and meta_query (#522)
1 parent 56553b8 commit f349e8f

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

features/post.feature

+29-6
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,35 @@ Feature: Manage WordPress posts
365365
| Publish post | publish-post | publish |
366366
| Sample Page | sample-page | publish |
367367

368-
When I run `wp post create --post_title='old post' --post_date='2023-01-24T09:52:00.000Z'`
369-
And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'`
370-
And I run `wp post list --field=post_title --date_query='{"before":{"year":"2024"}}'`
371-
Then STDOUT should contain:
368+
Scenario: List posts with date query
369+
When I run `wp post create --post_title='old post' --post_date='2023-01-24T09:52:00.000Z'`
370+
And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'`
371+
And I run `wp post list --field=post_title --date_query='{"before":{"year":"2024"}}'`
372+
Then STDOUT should contain:
372373
"""
373374
old post
374375
"""
375-
And STDOUT should not contain:
376-
"""
376+
And STDOUT should not contain:
377+
"""
377378
new post
378379
"""
379380

381+
Scenario: List posts with tax query
382+
When I run `wp term create category "First Category" --porcelain`
383+
When I run `wp term create category "Second Category" --porcelain`
384+
When I run `wp post create --post_title='post-1' --post_category="First Category"`
385+
When I run `wp post create --post_title='post-2' --post_category="Second Category"`
386+
And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'`
387+
And I run `wp post list --field=post_title --tax_query='[{"taxonomy":"category","field":"slug","terms":"first-category"}]'`
388+
Then STDOUT should contain:
389+
"""
390+
post-1
391+
"""
392+
And STDOUT should not contain:
393+
"""
394+
post-2
395+
"""
396+
380397
Scenario: Update categories on a post
381398
When I run `wp term create category "Test Category" --porcelain`
382399
Then save STDOUT as {TERM_ID}
@@ -427,6 +444,12 @@ Feature: Manage WordPress posts
427444
| {POST_ID} | key2 | value2b |
428445
| {POST_ID} | key3 | value3 |
429446

447+
When I run `wp post list --field=post_title --meta_query='[{"key":"key2","value":"value2b"}]'`
448+
Then STDOUT should contain:
449+
"""
450+
Test Post
451+
"""
452+
430453
@less-than-wp-4.4
431454
Scenario: Creating/updating posts with meta keys for WP < 4.4 has no effect so should give warning
432455
When I try `wp post create --post_title='Test Post' --post_content='Test post content' --meta_input='{"key1":"value1","key2":"value2"}' --porcelain`

src/Post_Command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ public function list_( $args, $assoc_args ) {
636636
'posts_per_page' => -1,
637637
'post_status' => 'any',
638638
];
639-
$array_arguments = [ 'date_query' ];
639+
$array_arguments = [ 'date_query', 'tax_query', 'meta_query' ];
640640
$assoc_args = Utils\parse_shell_arrays( $assoc_args, $array_arguments );
641641
$query_args = array_merge( $defaults, $assoc_args );
642642
$query_args = self::process_csv_arguments_to_arrays( $query_args );

0 commit comments

Comments
 (0)