【发布时间】:2013-12-04 19:35:16
【问题描述】:
在我的网站上发布帖子后,我正在编写一个发送邮件的函数,但问题如下:
如果我编辑已发布的帖子,则每次我更新已发布的帖子时都会发送一封新邮件。
这是我写的函数:
function send_mails($post_ID) {
global $wpdb;
$post = get_post($post_ID);
if ( !wp_is_post_revision( $post_ID ) ) {
$contenido = $post->post_content;
$excerpt = substr($contenido,0,255);
$permalink = get_permalink($post_ID);
$authorURL = get_author_posts_url($post->post_author);
$title = $post->post_title;
$result = $wpdb->get_results("SELECT * FROM wp_subscribe", ARRAY_A);
$origen = "XXXX";
$headers = "From: $origen\r\n";
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
foreach($result as $row){
// A lot of code for styling the mail-..
mail($row['email'],$title,$contenido,$headers);
}
}
return $post_ID;
}
add_action( 'publish_post', 'send_mails' );
有什么问题吗?或者我错过了一些功能来检查它是否是一个编辑过的帖子?
提前谢谢你
【问题讨论】:
-
新帖子不会是修订版...
-
我也是这样。但每次我更新网站上已经存在的帖子时,都会发送另一封邮件