Skip to content

Commit

Permalink
Merge pull request #520 from sabithahmd/fix/519-fix-date-query-not-wo…
Browse files Browse the repository at this point in the history
…rking-in-post-list

`wp post list`: Add JSON input support for `date_query` argument
  • Loading branch information
swissspidy authored Feb 18, 2025
2 parents 557c2de + d9d24c5 commit 56553b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions features/post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ 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:
"""
old post
"""
And STDOUT should not contain:
"""
new post
"""

Scenario: Update categories on a post
When I run `wp term create category "Test Category" --porcelain`
Then save STDOUT as {TERM_ID}
Expand Down
8 changes: 5 additions & 3 deletions src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,14 @@ protected function delete_callback( $post_id, $assoc_args ) {
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );

$defaults = [
$defaults = [
'posts_per_page' => -1,
'post_status' => 'any',
];
$query_args = array_merge( $defaults, $assoc_args );
$query_args = self::process_csv_arguments_to_arrays( $query_args );
$array_arguments = [ 'date_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 );
if ( isset( $query_args['post_type'] ) && 'any' !== $query_args['post_type'] ) {
$query_args['post_type'] = explode( ',', $query_args['post_type'] );
}
Expand Down

0 comments on commit 56553b8

Please sign in to comment.