Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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