admin管理员组文章数量:1307752
I am trying to send the featured image with other details by email to admin. Everything is working well except that the featured image is sent to email only when the post is edited from admin. If edited from frontend all the details are sent except the image.
I don't know why.
Here's the code:
// send email on creation or update of a campaign
add_action( 'save_post', 'campaign_updated_send_email' );
function campaign_updated_send_email( $post_id ) {
//check post type is product
$ptype = get_post_type( $post_id );
if ( $ptype === 'product') {
//verify campaign/product is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
//get the post status
$mypoststatus = get_post_status( $post_id );
// get the campaign image
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' );
$subject = '[Campaign updated:]'.$post_title;
$message = "A campaign has been updated2:\n\n";
$message = "<a href='". $post_url. "'><img src=".$image[0]." width=250></a>\n\n";
$message .= "<br><a href='". $post_url. "'><h3>" .$post_title. "</h3></a><h3>Current Status:<U>".$mypoststatus."</U></h3>\n\n";
$headers = array('Content-Type: text/html; charset=UTF-8');
//send email to admin
wp_mail( get_option( 'admin_email' ), $subject, $message, $headers);
}
}
}
本文标签: custom post typesSending current featured image to email
版权声明:本文标题:custom post types - Sending current featured image to email 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741810855a2398785.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论