Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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? –  m0r7if3r 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. –  m0r7if3r Jan 10 '12 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);
share|improve this answer

Your Answer

 
discard

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.