• userword

    (@userword)


    DELETE a,b,c
    FROM wp_posts a
    LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
    LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
    WHERE a.post_type = 'revision'

    it is supposed to delete post revisions and relatioships to them, is it safe, does delete it all as promised.

Viewing 5 replies - 1 through 5 (of 5 total)
  • MichaelH

    (@michaelh)

    I would think that this is enough:

    DELETE FROM wp_posts WHERE post_type = "revision";

    but also look at:
    https://www.ads-software.com/extend/plugins/delete-revision/

    Always backup your database before doing anything like this!

    Thread Starter userword

    (@userword)

    that is the line i find everywhere but on some other places they say there is some kind of relationship established between posts included revisions and those extra lines are supposed to delete them

    i am a bit lost as im not a programmer. anyway i agree you should backupp data base before doing anything strange. And about the plugin i know there is but i dont feel right using a plugin that is gonna play with my database all the time deleting things. just imagine it gets no update at some point while wordpress does get it, and some incompatibility make the plugin break database.

    i have hard time trusting in any code not coming from wordpress team.

    mrmist

    (@mrmist)

    You should be using INNER JOINs for this if your inention is simply to delete every row based on the WHERE a.post_type = 'revision' criteria.

    DELETE a,b,c is not standard SQL, though it may work in mysql.

    a,b,c are aliases … There’s nothing wrong with using aliases if used correctly..

    I think mrmist is right, i’m not entirely sure the left joins are correct..

    More on joins:
    https://dev.mysql.com/doc/refman/5.1/en/join.html

    Please don’t just assume it’s right, refer to the docs and confirm what needs to be changed, if anything.

    I’m not 100% sure, but i think b and c should be removed from the first line, leaving them as optional joins (if a match exists, delete it, else ignore), otherwise you’ll only get deletes where there are matches across the 3 tables (not when there’s only matches in the first, which is likely what you’d want). I could be wrong…

    Of course, what you could do (to test), would be to install another copy of WordPress, locally, sub directory, whatever!.. import your database, then run the query on the copy install… that way you put nothing at risk and you can see the results without touching your main install (or even quicker, just make a copy of the database and run the query directly in phpmyadmin on the new database).

    henkholland

    (@henkholland)

    You definitely want one that also cleans up wp_post_meta since that one has more lines than wp_posts

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Is this code safe to delete post revisions’ is closed to new replies.