Bulk delete (custom type) posts that are not visible on website

We have a custom post type with over 16.000 posts in database. Each post has a custom meta data 'expiry date'.

We have a custom post type with over 16.000 posts in database. Each post has a custom meta data 'expiry date'.

We want to regularly delete old posts that have: 1. Expiry date older dan 2 years AND 2. are not visible on our website

Some 'expired' posts are still shown and I want to make sure these do not get deleted.

We have a custom post type with over 16.000 posts in database. Each post has a custom meta data 'expiry date'.

We want to regularly delete old posts that have: 1. Expiry date older dan 2 years AND 2. are not visible on our website

Some 'expired' posts are still shown and I want to make sure these do not get deleted.

Share Improve this question asked Nov 25, 2019 at 12:40 LoyensLoyens 134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I suggest you use MySQL "DELETE". See this article:

http://www.mysqltutorial/mysql-delete-join/

So, something like this:

DELETE wp_posts, wp_postmeta
FROM wp_posts
INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE meta_key = 'expiry date' AND meta_value <= '2017-11-27' AND post_status != 'publish'

NOTE: 'wp_' could be different depending what your table prefix is set to in your wp-config.php file.

This should get rid of all posts in the posts table and all of the meta records in the meta table. It will also get rid of drafts/revision.

DOUBLE NOTE: -SUPER IMPORTANT- Don't do this unless you have a backup of your database.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744964035a4603564.html

相关推荐

  • Bulk delete (custom type) posts that are not visible on website

    We have a custom post type with over 16.000 posts in database. Each post has a custom meta data 'expiry date'.

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信