这里有几件事你需要做,你需要修改你的add_action()
要接受其他参数,您需要指定是在更新之前使用数据,还是在更新之后使用数据。
尝试以下操作:
function send_media_emails($post_id, $post_after){
if(defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE)
return;
if(get_post_status($post_id) == \'draft\' or get_post_status($post_id) == \'pending\' or get_post_status($post_id) == \'trash\')
return;
$to = \'[email protected]\';
$subject = \'My Email Subject\';
$post = $post_after; // NOTE We\'re using the after post update data here
$body = \'<h1>\'.$post->post_title.\'</h1>\';
if(is_category){
$category = get_the_category();
$body .= \'<h2>Reason for Closure: <em>\'.$category[0]->cat_name .\'</em></h2>\';
}
$body .= \'<h3>This Cancellation/Delay was posted on \'.$post->post_date.\'</h3>\';
$body .= \'<p>\'.$post->post_content.\'</p>\';
$body .= \'<p>View this posting at \' . get_permalink($post_id) . \' or</p>\';
if(did_action(\'post_updated\') == 1){
wp_mail($to, $subject, $body);
}
}
add_action(\'post_updated\', \'send_media_emails\', 10, 2);
// NOTE we\'ve added 2 arguments to be accepted and also a priority of 10
有关
add_action()
参数可以是
found here 您可以在
post_updated
行动
here