X

WordPress code for notify members on new posts

If you want to notify your WordPress site users then here is a quick solution which work fine. Add below snippet to the functions.php of your wordpress theme and your users will get email notification once there is a new post.

 
function email_notification($post_ID)  {
    global $wpdb;
    $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
    $users = implode(",", $usersarray);
    mail($users, "New post on vishmax.com", 'Hi, there is a new post on http://www.vishmax.com');
    return $post_ID;
}
add_action('publish_post', 'email_notification');