Skip to content

Commit 56553b8

Browse files
authored
Merge pull request #520 from sabithahmd/fix/519-fix-date-query-not-working-in-post-list
`wp post list`: Add JSON input support for `date_query` argument
2 parents 557c2de + d9d24c5 commit 56553b8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

features/post.feature

+12
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ 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:
372+
"""
373+
old post
374+
"""
375+
And STDOUT should not contain:
376+
"""
377+
new post
378+
"""
379+
368380
Scenario: Update categories on a post
369381
When I run `wp term create category "Test Category" --porcelain`
370382
Then save STDOUT as {TERM_ID}

src/Post_Command.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,14 @@ protected function delete_callback( $post_id, $assoc_args ) {
632632
public function list_( $args, $assoc_args ) {
633633
$formatter = $this->get_formatter( $assoc_args );
634634

635-
$defaults = [
635+
$defaults = [
636636
'posts_per_page' => -1,
637637
'post_status' => 'any',
638638
];
639-
$query_args = array_merge( $defaults, $assoc_args );
640-
$query_args = self::process_csv_arguments_to_arrays( $query_args );
639+
$array_arguments = [ 'date_query' ];
640+
$assoc_args = Utils\parse_shell_arrays( $assoc_args, $array_arguments );
641+
$query_args = array_merge( $defaults, $assoc_args );
642+
$query_args = self::process_csv_arguments_to_arrays( $query_args );
641643
if ( isset( $query_args['post_type'] ) && 'any' !== $query_args['post_type'] ) {
642644
$query_args['post_type'] = explode( ',', $query_args['post_type'] );
643645
}

0 commit comments

Comments
 (0)