Support » Fixing WordPress » Doubts about a proper mysql wordpress query, please, could you confirm ?

  • Hello,

    I must delete from a blog database every tag that isn’t present in more than one post. (Another way to tell it, every tag that is only present in zero or 1 post).

    However, to be frank, this is beyond my knowledge, I can only rely on the explanations I found online. Unfortunately, today this is a very important operation, and if it were to screw up the database the effects would be problematic.
    Let’s say that today is not just playing around and restoring a backup after a pair of hours if something’s broken, and calling it okay.

    Please, could I ask if the mysql lines that follow are the proper code to delete from a wordpress database all the tags that are not present in more than one post ?

    DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 )
    
    DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)

    If you see there is something wrong with it, please, pretty please with sugar on top, could you tell me ?
    Thank you VERY MUCH ! 🙂

Viewing 1 replies (of 1 total)
  • Thread Starter Sabinou

    (@sabinou1)

    Ah, a correction, I’d also have to run

    DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 1 )

    Or else that would only take care of the tags present in zero posts.

    And I just discovered the database was so huge it couldn’t be properly backed up anyway -_-

    Would someone know, please, if that’s the proper syntax ?
    Thank you very much 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Doubts about a proper mysql wordpress query, please, could you confirm ?’ is closed to new replies.