How to Remove Two (Related) wp_postmeta Rows?

After 5 hours of searching finally I wrote the SQL query and that is-

DELETE FROM {$wpdb->postmeta} 
WHERE  post_id IN (SELECT post_id 
                   FROM   (SELECT post_id 
                           FROM   {$wpdb->postmeta} 
                           WHERE  meta_key LIKE '_thumbnail_id' 
                                  AND post_id IN(SELECT post_id 
                                                 WHERE  meta_key LIKE 'rafi')) 
                          AS s) 

I saw your answer above, but using this kinda SQL query for this kinda problem is best practice as well as better.

Hope this helps.

Leave a Comment