我正在尝试为我的网站编写缓存插件。如何控制帖子或页面是否更新或添加了新页面或帖子
我如何控制帖子是否更新
2 个回复
SO网友:Pribhav
在插件的主功能文件中添加以下操作
add_action( \'wp_insert_post\', \'my_project_updated_post\', 10, 3 );
function my_project_updated_post( $post_id, $post, $update ) {
// your code goes here
// Every time you will get updated or newly created post id here.
}
SO网友:Sebastian Kurzynowski
无论何时更新或创建帖子或页面,都会触发操作挂钩save_post
. 发生时,可以调用函数:
add_action( \'save_post\', function( $post_or_page_id ) {
// Trigger your cache function or update options etc.
}, 10, 1 );
结束