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
 INNER
  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.

Comments

    No comments yet..