WordPress 自动删除自定义元字段
假设我有一个名为“debut”的自定义元字段,我希望在 x 天(例如 30 天)后将其从帖子/数据库中删除,但帖子仍然保持完整,只是没有“debut”的值。我该怎么做呢?
Lets say I have a custom meta field called "debut" and I want after x amount of days(Ex 30 days) it to be deleted from the post/db but the post is still to remain intact just without the value of "debut". How would I go about doing that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会创建一个简单的插件,挂钩到 WordPress 的加载状态,然后删除符合您标准的帖子元...
未经测试,只是从我的脑海中浮现出来,小心您用它做什么,可能很危险并删除所有帖子元...:)
这将是完整的请求,但请注意,没有添加元的日期。所以我采用帖子的最后修改日期。但如果用户修改了帖子,则元数据在 30 天之内不会被删除。
注意,我不确定这是否有效,因为 meta_value 的数据类型是 varchar,但如果转换有效,也许它不会抛出错误。
I would create a simple plugin that hooks to the loaded state of wordpress and just delete the post meta that meet your criterias...
Not tested, just got that off the top of my head, becareful what you do with that, can be dangerous and delete all your post metas... :)
That would be the full request, note tho, there are no dates when a META was added. So i'm taking the last modified date of the post. But if a user modifies the post then the meta won't be deleted before another 30 days.
Note, i'm not sure this will work since the data type of meta_value is a varchar, but if the conversion works, maybe it will not throw off errors.