Skip to content

Commit 37df404

Browse files
committed
wp post list: Add JSON input support for tax_query argument
1 parent 56553b8 commit 37df404

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

features/post.feature

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,38 @@ 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+
And save STDOUT as {TERM_ID}
384+
And I run `wp term create category "Second Category" --porcelain`
385+
And save STDOUT as {SECOND_TERM_ID}
386+
387+
When I run `wp post create --post_title='post-1' --post_category="First Category"`
388+
When I run `wp post create --post_title='post-2' --post_category="Second Category"`
389+
And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'`
390+
And I run `wp post list --field=post_title --tax_query='[{"taxonomy":"category","field":"slug","terms":"first-category"}]'`
391+
Then STDOUT should contain:
392+
"""
393+
post-1
394+
"""
395+
And STDOUT should not contain:
396+
"""
397+
post-2
398+
"""
399+
380400
Scenario: Update categories on a post
381401
When I run `wp term create category "Test Category" --porcelain`
382402
Then save STDOUT as {TERM_ID}

src/Post_Command.php

Lines changed: 1 addition & 1 deletion
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' ];
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)