plugins - How do I get fresh post data in post_publish hook?

I'm using the post_publish hook to do some operations in my plugin based on the post's taxonomies. If update a

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
}

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

相关推荐

  • plugins - How do I get fresh post data in post_publish hook?

    I'm using the post_publish hook to do some operations in my plugin based on the post's taxonomies. If update a

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信