Skip to main content
added 12 characters in body
Source Link

I'm working on a custom notification to be sent to contributors when their post is scheduled for publication, sharing the scheduled date of publication and various other information (title, category, etc).

The problem I'm having is that if I open up a pending post, set the date to the future, and then hit schedule, the notification doesn't include the post's scheduled publication date, it includes the post's original submission date.

I assume the issue is that my function is firing before the database is updated with the post's new date and other updated information. Code is below - any help is much appreciated!

function scheduledNotification() {
   global $post;
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);
   $link = get_permalink($post->ID);
   $date = mysql2date('M j Y', $post->post_date);
   $category = get_the_category($post->ID);
   $category = $category[0]->cat_name;
  
   $message = "<p>Dear ".$author->user_firstname.",</p>".           
              "<p>We will be publishing your ".$category." article, ".$post->post_title.", on ".$date.".</p>";  
                                        
   $headers[] = 'From: Send Name <[email protected]>';
   $headers[] = 'Content-type: text/html';
   wp_mail($author->user_email, "Your Upcoming Post", $message, $headers);
}
 
add_action('pending_to_future', 'scheduledNotification');
add_action('approved_to_future', 'scheduledNotification');

I'm working on a custom notification to be sent to contributors when their post is scheduled for publication, sharing the scheduled date of publication and various other information (title, category, etc).

The problem I'm having is that if I open up a pending post, set the date to the future, and then hit schedule, the notification doesn't include the post's scheduled publication date, it includes the post's original submission date.

I assume the issue is that my function is firing before the database is updated with the post's new date and other updated information. Code is below - any help is much appreciated!

function scheduledNotification() {
   global $post;
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);
   $link = get_permalink($post->ID);
   $date = mysql2date('M j Y', $post->post_date);
   $category = get_the_category($post->ID);
   $category = $category[0]->cat_name;
  
   $message = "<p>Dear ".$author->user_firstname.",</p>".           
              "<p>We will be publishing your article, ".$post->post_title.", on ".$date.".</p>";  
                                        
   $headers[] = 'From: Send Name <[email protected]>';
   $headers[] = 'Content-type: text/html';
   wp_mail($author->user_email, "Your Upcoming Post", $message, $headers);
}
 
add_action('pending_to_future', 'scheduledNotification');
add_action('approved_to_future', 'scheduledNotification');

I'm working on a custom notification to be sent to contributors when their post is scheduled for publication, sharing the scheduled date of publication and various other information (title, category, etc).

The problem I'm having is that if I open up a pending post, set the date to the future, and then hit schedule, the notification doesn't include the post's scheduled publication date, it includes the post's original submission date.

I assume the issue is that my function is firing before the database is updated with the post's new date and other updated information. Code is below - any help is much appreciated!

function scheduledNotification() {
   global $post;
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);
   $link = get_permalink($post->ID);
   $date = mysql2date('M j Y', $post->post_date);
   $category = get_the_category($post->ID);
   $category = $category[0]->cat_name;
  
   $message = "<p>Dear ".$author->user_firstname.",</p>".           
              "<p>We will be publishing your ".$category." article, ".$post->post_title.", on ".$date.".</p>";  
                                        
   $headers[] = 'From: Send Name <[email protected]>';
   $headers[] = 'Content-type: text/html';
   wp_mail($author->user_email, "Your Upcoming Post", $message, $headers);
}
 
add_action('pending_to_future', 'scheduledNotification');
add_action('approved_to_future', 'scheduledNotification');
Source Link

Custom notification for contributors when posts are scheduled

I'm working on a custom notification to be sent to contributors when their post is scheduled for publication, sharing the scheduled date of publication and various other information (title, category, etc).

The problem I'm having is that if I open up a pending post, set the date to the future, and then hit schedule, the notification doesn't include the post's scheduled publication date, it includes the post's original submission date.

I assume the issue is that my function is firing before the database is updated with the post's new date and other updated information. Code is below - any help is much appreciated!

function scheduledNotification() {
   global $post;
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);
   $link = get_permalink($post->ID);
   $date = mysql2date('M j Y', $post->post_date);
   $category = get_the_category($post->ID);
   $category = $category[0]->cat_name;
  
   $message = "<p>Dear ".$author->user_firstname.",</p>".           
              "<p>We will be publishing your article, ".$post->post_title.", on ".$date.".</p>";  
                                        
   $headers[] = 'From: Send Name <[email protected]>';
   $headers[] = 'Content-type: text/html';
   wp_mail($author->user_email, "Your Upcoming Post", $message, $headers);
}
 
add_action('pending_to_future', 'scheduledNotification');
add_action('approved_to_future', 'scheduledNotification');