Wordpress SQL Delete Custom Message Types and Meta

I have the following SQL query that allows me to retrieve and delete all messages of a custom message type older than X days.

SELECT * FROM `wp_posts`
WHERE `post_type` = ‘clothing’
AND DATEDIFF(NOW(), `post_date`) > 2

DELETE * FROM `wp_posts`
WHERE `post_type` = ‘clothing’
AND DATEDIFF(NOW(), `post_date`) > 2

However, from what I read on the Internet, it seems that the code above does not really delete the message metadata, so I still have a bunch of data left over.

My question is, how can I change this code so that all related meta information is also removed from deleted messages?

thank

+4
source share
1 answer

, . WP wp_posts wp_postmeta post_id wp_postmeta. , . : wp_posts, delete cascade

delete
p,pm
from wp_posts p
join wp_postmeta pm on pm.post_id = p.id
where p.post_type = 'clothing'
and DATEDIFF(NOW(), p.post_date) > 2
+10

All Articles