From 0ddfaaa7cabb01c2d50bf00319722c96c3c5fa54 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Wed, 14 Feb 2024 10:45:41 +0545 Subject: [PATCH] Fix condition for comment count check --- features/comment-recount.feature | 4 ++-- src/Comment_Command.php | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/features/comment-recount.feature b/features/comment-recount.feature index 332fbe9e..538f235c 100644 --- a/features/comment-recount.feature +++ b/features/comment-recount.feature @@ -24,8 +24,8 @@ Feature: Recount comments on a post Updated post 1 comment count to 3. """ - When I run `wp comment recount 99999999` - Then STDOUT should be: + When I try `wp comment recount 99999999` + Then STDERR should be: """ Warning: Post 99999999 doesn't exist. """ diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 2b7172c2..1ff6b361 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -672,9 +672,8 @@ public function count( $args, $assoc_args ) { */ public function recount( $args ) { foreach ( $args as $id ) { - $post = get_post( $id ); - if ( $post ) { - wp_update_comment_count( $id ); + if ( wp_update_comment_count( $id ) ) { + $post = get_post( $id ); WP_CLI::log( "Updated post {$post->ID} comment count to {$post->comment_count}." ); } else { WP_CLI::warning( "Post {$id} doesn't exist." );