{"id":1319,"date":"2014-05-08T21:41:03","date_gmt":"2014-05-08T12:41:03","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=1319"},"modified":"2014-05-08T21:41:03","modified_gmt":"2014-05-08T12:41:03","slug":"how-to-manage-wordpress-comments-using-php-mysql","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/how-to-manage-wordpress-comments-using-php-mysql\/","title":{"rendered":"How to manage wordpress comments using php mysql"},"content":{"rendered":"<p>Here is way to manage your wordpress comments using php mysql queries.<\/p>\n<h2>Some things to note<\/h2>\n<ul>\n<li>Don\u2019t forget to do a backup of your database before testing any of the queries below.<\/li>\n<li>Don\u2019t forget to change the default table prefix\u00a0<code>wp_<\/code>\u00a0by the one used by your database.<\/li>\n<\/ul>\n<h2>Delete all spam comments<\/h2>\n<p>When you have over 100,000 spam comments in your spam queue, deleting them using the built-in \u201cdelete all spam\u201d button might result in a PHP memory error. To avoid this, just use this simple SQL request to delete all spam at once.<\/p>\n<pre>DELETE from wp_comments WHERE comment_approved = 'spam'<\/pre>\n<h2>Delete all comments between two dates<\/h2>\n<p>Had a \u201cspam attack\u201d for a limited time? Here is an easy way to delete all comments between two dates.<\/p>\n<pre>DELETE FROM wp_comments \r\nWHERE comment_date &gt; '2013-11-15 01:10:04'\r\nAND comment_date &lt;= '2013-11-20 00:10:04'<\/pre>\n<h2>Delete all pending comments<\/h2>\n<p>If your &#8220;pending comment&#8221; queue is filled with 99% spam comments and you don&#8217;t want to manually review each of them, here is a SQL command to instantly erase all pending comments.<\/p>\n<pre>DELETE FROM wp_comments WHERE comment_approved = '0'<\/pre>\n<h2>Disable comments on all posts at once<\/h2>\n<p>Want to disable comments on all of your posts? Instead of closing comments on all your posts the one after the other, why not using this super simple SQL query?<\/p>\n<pre>UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE comment_status = 'open'<\/pre>\n<h2>Disable comments on older posts<\/h2>\n<p>To limit spam, why not closing comments on older posts? Here is the SQL to automatically close comments on all posts older than January 1, 2014:<\/p>\n<pre>UPDATE wp_posts SET comment_status = 'closed' WHERE post_date &lt; '2014-01-01' AND post_status = 'publish'<\/pre>\n<p><strong>Source:\u00a0<a href=\"http:\/\/perishablepress.com\/wordpress-discussion-management-enable-or-disable-comments-and-pingbacks-via-sql\/\" target=\"_blank\" rel=\"noopener\">http:\/\/perishablepress.com\/wordpress-discussion-management&#8230;<\/a><\/strong><\/p>\n<h2>delete comments with a specific url<\/h2>\n<p>Even if you&#8217;re careful when approving new comments, sometimes you might just forget to visit the commenter url and detect a long time after that the linked site is spammy. Here is a very easy way to bulk delete all comments with a specific url, using a simple SQL query.<\/p>\n<pre>DELETE from wp_comments WHERE comment_author_url LIKE \"%nastyspamurl%\" ;<\/pre>\n<p><strong>Source:\u00a0<a href=\"http:\/\/www.wprecipes.com\/wordpress-tip-bulk-delete-comments-with-a-specific-url\" target=\"_blank\" rel=\"noopener\">http:\/\/www.wprecipes.com\/wordpress-tip-bulk-delete-comments&#8230;<\/a><\/strong><\/p>\n<h2>Search and replace comment text<\/h2>\n<p>If there&#8217;s a specific word or sentence that you want to replace in all comments, here is a very handy SQL query which use the mysql\u00a0<code>REPLACE<\/code>\u00a0function.<\/p>\n<pre>UPDATE wp_comments SET `comment_content` = REPLACE (`comment_content`, 'OriginalText', 'ReplacedText')<\/pre>\n<h2>Globally enable comments for registered users only<\/h2>\n<p>A very effective way to dramatically decrease the amount of received spam comment is to enable comments for registered users only. Instead of doing it on each post, here&#8217;s a SQL query to run in oder to do it on all posts at once.<\/p>\n<pre>UPDATE wp_posts SET comment_status = 'registered_only'<\/pre>\n<p><strong>Source:\u00a0<a href=\"http:\/\/digwp.com\/2010\/08\/wordpress-sql-comments\/\" target=\"_blank\" rel=\"noopener\">http:\/\/digwp.com\/2010\/08\/wordpress-sql-comments\/<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is way to manage your wordpress comments using php mysql queries. Some things to note Don\u2019t forget to do a backup of your database before testing any of the queries below. Don\u2019t forget to change the default table prefix\u00a0wp_\u00a0by the one used by your database. Delete all spam comments When you have over 100,000 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[681],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-how-to-manage-wordpress-comments-using-php-mysql"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/1319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=1319"}],"version-history":[{"count":1,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}