Skip to content

Commit

Permalink
Merge pull request #469 from ernilambar/464-fix-comment-recount
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Feb 14, 2024
2 parents 27f0bf0 + 0ddfaaa commit be561cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions features/comment-recount.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ Feature: Recount comments on a post
"""
Updated post 1 comment count to 3.
"""

When I try `wp comment recount 99999999`
Then STDERR should be:
"""
Warning: Post 99999999 doesn't exist.
"""
7 changes: 3 additions & 4 deletions src/Comment_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,11 @@ public function count( $args, $assoc_args ) {
*/
public function recount( $args ) {
foreach ( $args as $id ) {
wp_update_comment_count( $id );
$post = get_post( $id );
if ( $post ) {
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 {$post->ID} doesn't exist." );
WP_CLI::warning( "Post {$id} doesn't exist." );
}
}
}
Expand Down

0 comments on commit be561cf

Please sign in to comment.