wp_mail sending old content from post
There’s a few things you need to do here, you need to modify your add_action()
to accept additional arguments and you need to specify whether to use the data before the update or the data after the update.
Try something like this:
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
More information on the add_action()
arguments can be found here and you can see an example of the before and after post data on the post_updated
action here