这里有一种删除所有修订的方法,除了last one (我知道这不是最初问的问题,但我希望这有助于其他人使用类似的解决方案)。
Step 1. 使用要保留的修订创建临时表:
DROP TABLE IF EXISTS t_keep_revisions;
CREATE TEMPORARY TABLE t_keep_revisions AS (
SELECT
MAX(p.ID) as ID,
p.post_parent
FROM wp_posts p
WHERE p.post_type = \'revision\'
GROUP BY p.post_parent
ORDER BY p.post_parent
);
Step 2. 删除所有修订帖子,ID位于上表中的帖子除外
DELETE FROM wp_posts
WHERE post_type = \'revision\'
AND ID NOT IN (
SELECT ID
FROM t_keep_revisions
);
Step 3. 从wp\\U Posteta中删除孤立元数据
DELETE FROM wp_postmeta
WHERE post_id NOT IN (
SELECT ID FROM wp_posts
)