Created
April 1, 2015 10:51
-
-
Save jeffreyvr/f81010172de15672e7d5 to your computer and use it in GitHub Desktop.
WordPress recount comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Put this file in the root of your WordPress installation. | |
* When done remove it! | |
*/ | |
include 'wp-blog-header.php'; | |
global $wpdb; | |
$wp_posts = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_status = 'publish'"); | |
foreach( $wp_posts as $post ) { | |
$post_id = $post->ID; | |
$comment_count = $wpdb->get_var("SELECT COUNT(*) AS comment_cnt FROM wp_comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'"); | |
$wpdb->query("UPDATE wp_posts SET comment_count = '$comment_count' WHERE ID = '$post_id'"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment