Skip to content

Commit be561cf

Browse files
authored
Merge pull request #469 from ernilambar/464-fix-comment-recount
2 parents 27f0bf0 + 0ddfaaa commit be561cf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

features/comment-recount.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ Feature: Recount comments on a post
2323
"""
2424
Updated post 1 comment count to 3.
2525
"""
26+
27+
When I try `wp comment recount 99999999`
28+
Then STDERR should be:
29+
"""
30+
Warning: Post 99999999 doesn't exist.
31+
"""

src/Comment_Command.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,11 @@ public function count( $args, $assoc_args ) {
672672
*/
673673
public function recount( $args ) {
674674
foreach ( $args as $id ) {
675-
wp_update_comment_count( $id );
676-
$post = get_post( $id );
677-
if ( $post ) {
675+
if ( wp_update_comment_count( $id ) ) {
676+
$post = get_post( $id );
678677
WP_CLI::log( "Updated post {$post->ID} comment count to {$post->comment_count}." );
679678
} else {
680-
WP_CLI::warning( "Post {$post->ID} doesn't exist." );
679+
WP_CLI::warning( "Post {$id} doesn't exist." );
681680
}
682681
}
683682
}

0 commit comments

Comments
 (0)