WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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']

share|improve this question
Does it have to be SQL only? – mor7ifer Jan 10 '12 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 '12 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 '12 at 20:22
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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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