Posted on

Example to bulk delete non-popular WordPress posts by MySQL query

SELECT 
COUNT(DISTINCT p.id)
FROM
wp_posts p
LEFT JOIN
wp_postmeta m ON m.post_id = p.id AND meta_key = 'views'
WHERE
m.meta_value IS NULL
AND DATE_ADD(CURRENT_DATE,
INTERVAL - 88 DAY);

DELETE p FROM wp_posts p
LEFT JOIN
wp_postmeta m ON m.post_id = p.id AND meta_key = 'views'
WHERE
m.meta_value IS NULL
AND DATE_ADD(CURRENT_DATE,
INTERVAL - 88 DAY);
Leave a Reply

Your email address will not be published. Required fields are marked *