From 37df40428cae378926cdf555525cf7b3115a4c5d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 21 Feb 2025 11:22:58 +0100 Subject: [PATCH 1/3] `wp post list`: Add JSON input support for `tax_query` argument --- features/post.feature | 32 ++++++++++++++++++++++++++------ src/Post_Command.php | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/features/post.feature b/features/post.feature index d40eb996..4084f075 100644 --- a/features/post.feature +++ b/features/post.feature @@ -365,18 +365,38 @@ 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` + And save STDOUT as {TERM_ID} + And I run `wp term create category "Second Category" --porcelain` + And save STDOUT as {SECOND_TERM_ID} + + 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} diff --git a/src/Post_Command.php b/src/Post_Command.php index 0bf4634d..eaad0d8e 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' ]; $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 ); From e2aa535f9b1065191fdfb46323335e8252dbcd2e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 21 Feb 2025 11:23:04 +0100 Subject: [PATCH 2/3] Add `meta_query` as well --- features/post.feature | 6 ++++++ src/Post_Command.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/features/post.feature b/features/post.feature index 4084f075..06cc9354 100644 --- a/features/post.feature +++ b/features/post.feature @@ -447,6 +447,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 eaad0d8e..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', 'tax_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 ); From b4782aac201a75a2e499d824c633678d6590d7e6 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 23 Feb 2025 17:47:39 +0100 Subject: [PATCH 3/3] Dont save output --- features/post.feature | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/features/post.feature b/features/post.feature index 06cc9354..874eb830 100644 --- a/features/post.feature +++ b/features/post.feature @@ -380,10 +380,7 @@ Feature: Manage WordPress posts Scenario: List posts with tax query When I run `wp term create category "First Category" --porcelain` - And save STDOUT as {TERM_ID} - And I run `wp term create category "Second Category" --porcelain` - And save STDOUT as {SECOND_TERM_ID} - + 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'`