【发布时间】:2015-07-09 04:00:42
【问题描述】:
当我挂钩媒体上传(我使用add_attachment挂钩)时,有没有办法编辑添加到数据库中的值?
基本上,我想做的是:
媒体上传挂钩
根据 $attachment_id 编辑/更新 wp_posts 表中的字段值(post_status)
返回
函数如下:
add_filter('add_attachment', 'handle_upload' );
function handle_upload($attachment_id){
//get attachment ID from database: how? I believe that at this point the database is not populated with the new post (media)
// update the post_status field from wp_posts table with some value
//return
}
这可能吗?
提前致谢!
【问题讨论】:
-
您想收集什么信息?或者你想更新什么?
-
嗨,我正在开发一个插件,它不会在上传后立即显示图像,而是在审核后显示。所以,我需要做的是: - 挂钩媒体上传事件(例如:add_attachment,如果这不是正确的,请指向另一个) - 将帖子的状态更改为“auto_draft”
-
啊,所以当一个项目被上传并添加到媒体库时,您需要设置一个审核标志。你来对地方了。让我挖掘一下,看看能否为您找到更多信息。
-
太棒了!谢谢!我使用了“wp_update_post”,但我认为我尝试过早地编辑标志(在它登陆数据库之前)
-
我设法做到了。我会发布结果!感谢您的支持!
标签: php wordpress upload media attachment