2015-02-07 26 views
0

我已经构建了一个函数,用于发送包含所有发布信息发布或更新时间的电子邮件。它的工作方式应该像电子邮件一样,除了发布的标题外,它还包含所有内容被困了几个小时。但是,如果我更新帖子,我会收到帖子标题,但是当我发帖时没有任何信息。只有帖子标题。我很感激你能给予的帮助。wp_mail发送除标题外的所有内容

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 = get_post(); 
    $post = $post_after; 
    //$post_title = get_the_title($post_id); 
    $body = '<h1>'.get_the_title($post_id).'</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); 

回答

0

我想通了。我从一个自定义术语拉出帖子标题,所以它没有抓住它。所以我必须首先从选定的术语中获得标题。

$terms = wp_get_post_terms($post_id, 'regions'); 
$title = $title ? $title : $terms[0]->name; 

然后在电子邮件中发送$ title变量。如果其他人有这种设置或问题

相关问题