I am trying to clean up a DB of 4000+ posts and the editors TAGGED the posts that they want to keep with an "audit2017" tag. Is there a way with SQL to select all posts *without this tag and delete them?

I am not very experienced with SQL but can manage this if I had the right query.

Any help appreciated, thanks!


Was looking into this to help you come with a solution. I'm not able to find one for the sql panel, but I guess you could first get all the posts that do not have that tag id (as shown here https://codex.wordpress.org/Class_Reference/WP_Query):

$query = new WP_Query( array( 'tag__not_in' => array( 37, 47 ) ) );

And then delete them using some php:

  • https://developer.wordpress.org/reference/functions/wp_delete_post/
  • another example: http://wordpress.stackexchange.com/questions/48214/manually-delete-post-from-database

This plugin was perfect if the client was doing the exact opposite, adding a specific tag to all the posts he DOESN'T WANT to keep: https://wordpress.org/plugins/bulk-delete/

Hope this info is helpful.

  • Thanks Mihai!! I don't really know how / where to put in that kind of query. Would I have to write a plugin? – pixelkicker Apr 3 '17 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.