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