diff --git a/features/post.feature b/features/post.feature index d40eb996..874eb830 100644 --- a/features/post.feature +++ b/features/post.feature @@ -365,18 +365,35 @@ Feature: Manage WordPress posts | Publish post | publish-post | publish | | Sample Page | sample-page | publish | - When I run `wp post create --post_title='old post' --post_date='2023-01-24T09:52:00.000Z'` - And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'` - And I run `wp post list --field=post_title --date_query='{"before":{"year":"2024"}}'` - Then STDOUT should contain: + Scenario: List posts with date query + When I run `wp post create --post_title='old post' --post_date='2023-01-24T09:52:00.000Z'` + And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'` + And I run `wp post list --field=post_title --date_query='{"before":{"year":"2024"}}'` + Then STDOUT should contain: """ old post """ - And STDOUT should not contain: - """ + And STDOUT should not contain: + """ new post """ + Scenario: List posts with tax query + When I run `wp term create category "First Category" --porcelain` + When I run `wp term create category "Second Category" --porcelain` + When I run `wp post create --post_title='post-1' --post_category="First Category"` + When I run `wp post create --post_title='post-2' --post_category="Second Category"` + And I run `wp post create --post_title='new post' --post_date='2025-01-24T09:52:00.000Z'` + And I run `wp post list --field=post_title --tax_query='[{"taxonomy":"category","field":"slug","terms":"first-category"}]'` + Then STDOUT should contain: + """ + post-1 + """ + And STDOUT should not contain: + """ + post-2 + """ + Scenario: Update categories on a post When I run `wp term create category "Test Category" --porcelain` Then save STDOUT as {TERM_ID} @@ -427,6 +444,12 @@ Feature: Manage WordPress posts | {POST_ID} | key2 | value2b | | {POST_ID} | key3 | value3 | + When I run `wp post list --field=post_title --meta_query='[{"key":"key2","value":"value2b"}]'` + Then STDOUT should contain: + """ + Test Post + """ + @less-than-wp-4.4 Scenario: Creating/updating posts with meta keys for WP < 4.4 has no effect so should give warning When I try `wp post create --post_title='Test Post' --post_content='Test post content' --meta_input='{"key1":"value1","key2":"value2"}' --porcelain` diff --git a/src/Post_Command.php b/src/Post_Command.php index 0bf4634d..a4a5ba42 100644 --- a/src/Post_Command.php +++ b/src/Post_Command.php @@ -636,7 +636,7 @@ public function list_( $args, $assoc_args ) { 'posts_per_page' => -1, 'post_status' => 'any', ]; - $array_arguments = [ 'date_query' ]; + $array_arguments = [ 'date_query', 'tax_query', 'meta_query' ]; $assoc_args = Utils\parse_shell_arrays( $assoc_args, $array_arguments ); $query_args = array_merge( $defaults, $assoc_args ); $query_args = self::process_csv_arguments_to_arrays( $query_args );