How to enable comments for all posts in wordpress

I had a problem with my blog recently that some plugin was disabling comments for older posts. Editing one-by-one and enabling comments back is a pain i know. Here is a simple function you can put in your functions.php to enable comments for all posts at once.

function enable_comments_for_all(){
	global $wpdb;
	$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open'")); // Enable comments
	$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET ping_status = 'open'")); // Enable trackbacks
} enable_comments_for_all();

This function needs to be run just once, so after you save the file, visit your site. Then either comment out this block or simply remove it so it won’t try this query every time a page is loaded.

I hope it helps you out.

NS Weight Release