Find and update WordPress posts with comments older than NNN days

March 12, 2018

I have a use case where I need to disable comments on posts in WordPress where the last comment was more than one year, or 365 days, ago. Posts can be found with this query: SELECT p.ID, p.post_title, p.post_date, p.comment_status, p.`ping_status` FROM wp_posts AS p WHERE p.ID IN ( SELECT c.comment_post_ID FROM wp_comments AS c