admin管理员组文章数量:1410712
I'm using the post_publish hook to do some operations in my plugin based on the post's taxonomies. If update a post, calling get_the_category($id)
returns the categories for the post version before the update, not after it, which messes up the operations I'm running.
For example, if I publish a post with category id's 20 and 21, and try to get the post's categories in the post_publish hook, it works. If I then edit the post so it only has category 20, and try to the get categories in the post_publish hook, it returns categories 20 and 21, even though the update only has category 20. If I edit the post title, that is accurately reflected in the $post
argument.
I have read this similar question, but that one concerns meta values, not taxonomies, and I'm not sure how to apply it's answer here.
How do I get the fresh taxonomy data? This also happens if I use the save_post hook.
add_action("publish_post", "process_published_post", 10, 2);
function process_published_post($id, $post) {
$categories = get_the_category($id);
//Categories here are old when post is being updated
}
本文标签: pluginsHow do I get fresh post data in postpublish hook
版权声明:本文标题:plugins - How do I get fresh post data in post_publish hook? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745040903a2639065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论