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

Leave a reply

Feel free to ask questions or make comments.


    No comments yet..