[英]How to add a record simultaneously in another table when a new blog post is inserted using wp_insert_post?
I am adding a new blog post using wp_insert_post
. 我正在使用wp_insert_post
添加一个新的博客文章。 Is it possible to show a notification message to all the other users that a person posted a new blog post. 是否可以向其他所有用户显示某人发布了新博客帖子的通知消息。
I need to insert a record in another table when wp_insert_post
function occurs. wp_insert_post
函数发生时,我需要在另一个表中插入一条记录。
I am trying to do Follow feature. 我正在尝试执行关注功能。 If some user is following me, he should get my newly added blog post as a notification. 如果某个用户在关注我,他应该获得我新添加的博客帖子作为通知。
Any helps...!! 任何帮助...!
thanks 谢谢
You can use wp_insert_post
hook. 您可以使用wp_insert_post
挂钩。 As it says in the docs: The wp_insert_post
action fires once a post has been saved. 就像在docs中说的:保存帖子后,将触发wp_insert_post
操作。
function my_project_updated_send_email( $post_id, $post, $update ) {
// If this is a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )
return;
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= $post->post_title . ": " . $post_url;
// Send email to admin.
wp_mail( 'admin@example.com', $subject, $message );
}
add_action( 'wp_insert_post', 'my_project_updated_send_email', 10, 3 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.