Mysql delete all posts that have a given meta_key

2019-08-07 06:13发布

This question already has an answer here:

I have a wordpress site that has some meta_key's asigned to my posts. I want to delete all posts in mysql that has the meta_key value acest_meta. With this SQL command :

SELECT `post_id`
FROM `wp_postmeta`
WHERE `meta_key` 
LIKE 'acest_meta' 
ORDER BY `wp_postmeta`.`post_id` ASC

i can see all the id's that contain that given meta_key but i don't have a delete check box neer. I see a message on top that say "Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available." How can i delete all those posts ?

3条回答
成全新的幸福
2楼-- · 2019-08-07 06:46

Using Mysql query you can use join in delete query

DELETE p.*,w.*
FROM `wp_postmeta` w
JOIN wp_posts p
 ON(p.ID = w.`post_id`)
WHERE w.`meta_key` LIKE 'acest_meta'

Above query will delete all posts and its meta data contains a meta_key as acest_meta

查看更多
仙女界的扛把子
3楼-- · 2019-08-07 06:48

you can delete with a select using an IN() statement and put the select in an IN like so

DELETE FROM `wp_postmeta` 
WHERE `post_id` IN 
(   SELECT `post_id`
    FROM `wp_postmeta`
    WHERE `meta_key` LIKE 'acest_meta' 
)
查看更多
Fickle 薄情
4楼-- · 2019-08-07 06:54
delete from wp_postmeta
 where post_id in
       (SELECT post_id FROM wp_postmeta WHERE meta_key = 'acest_meta')
查看更多
登录 后发表回答