edit_post_{$post->post_type}
云策文档标注
概述
edit_post_{$post->post_type} 是一个 WordPress 动作钩子,在现有文章更新后触发。它允许开发者根据文章类型执行自定义操作。
关键要点
- 这是一个动态钩子,钩子名称中的 $post->post_type 部分会根据文章类型 slug 动态变化。
- 钩子接收两个参数:$post_id(文章 ID)和 $post(WP_Post 对象)。
- 钩子从 WordPress 5.1.0 版本开始引入。
代码示例
do_action( "edit_post_{$post->post_type}", $post_id, $post );注意事项
- 钩子名称示例包括 edit_post_post 和 edit_post_page,分别对应文章和页面类型。
- 相关函数包括 wp_insert_post()、wp_publish_post() 等,用于插入、发布或更新文章。
原文内容
Fires once an existing post has been updated.
Description
The dynamic portion of the hook name, $post->post_type, refers to the post type slug.
Possible hook names include:
edit_post_postedit_post_page
Parameters
$post_idint-
Post ID.
$postWP_Post-
Post object.
Source
do_action( "edit_post_{$post->post_type}", $post_id, $post );
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |