• Resolved More Than God

    (@more-than-god)


    Good day, intending to make query for purging old revisions, but getting error on line #27, any ideas to fix?

    DELETE pm FROM wp_postmeta pm WHERE pm.post_id IN (
    SELECT p.ID
    FROM wp_posts p
    WHERE p.post_type = 'revision'
    AND p.ID NOT IN (
    SELECT recent_revisions.ID
    FROM (
    SELECT ID
    FROM wp_posts
    WHERE post_type = 'revision'
    ORDER BY post_parent,
    post_date DESC
    ) AS recent_revisions
    WHERE recent_revisions.ID IN (
    SELECT ID
    FROM (
    SELECT ID
    FROM wp_posts
    WHERE post_type = 'revision'
    GROUP BY post_parent
    HAVING COUNT(ID) > 15
    ) AS grouped_revisions
    )
    )
    );

    DELETE p FROM wp_posts p WHERE p.post_type = 'revision' AND p.ID NOT IN (
    SELECT recent_revisions.ID
    FROM (
    SELECT ID
    FROM wp_posts
    WHERE post_type = 'revision'
    ORDER BY post_parent,
    post_date DESC
    ) AS recent_revisions
    WHERE recent_revisions.ID IN (
    SELECT ID
    FROM (
    SELECT ID
    FROM wp_posts
    WHERE post_type = 'revision'
    GROUP BY post_parent
    HAVING COUNT(ID) > 15
    ) AS grouped_revisions
    )
    );
Viewing 1 replies (of 1 total)
  • Plugin Support Val Meow

    (@valwa)

    Hey @more-than-god! 👋

    SQL errors depend on your database service and version, so it can be challenging to identify the issue at a glance. Since this isn’t directly related to the plugin, I’m not sure how much help I can provide in this regard. Always ensure you back up your server before performing any operations with the plugin. Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Complex custom query?’ is closed to new replies.