plugin development - When does save_post hook fire on post saveupdate

In my plugin I want to update sitemap every time page or post is createdmodified. To achieve this I use save_post hook:

In my plugin I want to update sitemap every time page or post is created/modified. To achieve this I use save_post hook:

add_action( 'save_post', 'update_sitemap', 10, 3);

Upon creating/saving/updating/deleting any page my callback method update_sitemap is fired but when i create/save/update/delete any post it doesn't seem to fire callback update_sitemap immediately.

I tested this for custom post types and it works immediately like for pages.

When I add 2 new regular posts, callback method is called once. Only after any further modification callback for 2nd post is fired.

Is this expected behaviour for save_post hook?

In my plugin I want to update sitemap every time page or post is created/modified. To achieve this I use save_post hook:

add_action( 'save_post', 'update_sitemap', 10, 3);

Upon creating/saving/updating/deleting any page my callback method update_sitemap is fired but when i create/save/update/delete any post it doesn't seem to fire callback update_sitemap immediately.

I tested this for custom post types and it works immediately like for pages.

When I add 2 new regular posts, callback method is called once. Only after any further modification callback for 2nd post is fired.

Is this expected behaviour for save_post hook?

Share Improve this question edited Jul 10, 2019 at 10:35 Krzysztof Chodera asked Jul 10, 2019 at 10:25 Krzysztof ChoderaKrzysztof Chodera 317 bronze badges 1
  • It's impossible to guess what the update_sitemap() function do. – Max Yudin Commented Jul 10, 2019 at 10:37
Add a comment  | 

1 Answer 1

Reset to default 2

save_post is fired at the end of wp_insert_post() which is the core function that's run whenever a post is inserted or updated (wp_update_post() calls it internally). This includes when the post is updated via the classic editor and the block editor (Gutenberg), as well whenever it's updated via the REST API. The only reason it wouldn't fire is if the post was being updated via SQL directly (via a plugin or otherwise), or when only post meta is updated via a function.

So no, this is not the expected behaviour. If your function isn't firing then it could be interference from another theme or plugin, or it could be an issue with the function itself, but there's not enough information in the question to say either way.

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

相关推荐

  • plugin development - When does save_post hook fire on post saveupdate

    In my plugin I want to update sitemap every time page or post is createdmodified. To achieve this I use save_post hook:

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信