SQL query delete post and postmeta by meta key and value

To delete all posts by a specific meta key and optionally meta value I run the following SQL query:

DELETE p, pm
  FROM wp_posts p
  JOIN wp_postmeta pm
    ON pm.post_id = p.ID
 WHERE pm.meta_key = 'meta_key_name'
   AND pm.meta_value = 'some value';
Robbert Vermeulen

Need help from a WordPress expert?

I would love to hear about your project and how I can help you achieve your goals