Thursday, August 2, 2012

Sending users email on post publish

function send_email_publish_post($post_ID) 
{ global $wpdb; $permalink = get_permalink( $post_ID ); 
 $query = "SELECT * FROM {$wpdb->users}"; 
 $users = $wpdb->get_results( $query);
 foreach($users as $user) 

$permalink = get_permalink( $post_ID ); 
$message="A New Post published. You can view the post details from the link ".$permalink." This is an auto generated notification. Please do not reply to it."; 
wp_mail( $user->user_email, "A New Post published", $message); 
 } 
return $post_ID; 

add_action('wp_publish_post','send_email_publish_post');

No comments:

Post a Comment