I'm looking for a simple SQL script that will delete posts where the post meta of that post id has some value ['x'].

DELETE FROM wp_posts WHERE post_id == wp_post_meta->post_id WHERE meta_value = ['x']

  • Does it have to be SQL only?
    – mor7ifer
    Jan 10, 2012 at 20:15
  • I'm not sure what an alternative would be but I just used an INNER JOIN and it did the trick.
    – AlxVallejo
    Jan 10, 2012 at 20:18
  • I was gonna suggest deleting from within a script by getting post objects with WP_Query and then iterating through them...mostly because handtyped sql is easy (for me at least) to botch. Kudos if you got it though.
    – mor7ifer
    Jan 10, 2012 at 20:22

1 Answer 1

DELETE wp_posts
FROM wp_posts
INNER JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID
WHERE (wp_postmeta.meta_key = 'InternalOnly' AND wp_postmeta.meta_value IS NOT NULL);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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