In my theme, I want to create the function that when a metabox value is changed, the author is notified.
Effectively, I have a custom metabox that loops through a certain level of user role (custom user role), with the <option value="<the user's ID>"
I was able to do this through changing the author with the following code:
function check_values($post_ID, $post_after, $post_before){
if( $post_after->post_author !== $post_before->post_author ) {
$author = $post_after->post_author; /* Post author ID. */
$name = get_the_author_meta( 'display_name', $author );
$email = get_the_author_meta( 'user_email', $author );
$title = $post_after->post_title;
$permalink = get_permalink( $ID );
$edit = get_edit_post_link( $ID, '' );
$to[] = sprintf( '%s <%s>', $name, $email );
$subject = sprintf( 'Published: %s', $title );
$message = sprintf ('Congratulations, %s! Your article “%s” has been published.' . "\n\n", $name, $title );
$message .= sprintf( 'View: %s', $permalink );
$headers[] = '';
wp_mail( $to, $subject, $message, $headers );
}
}
add_action( 'post_updated', 'check_values', 10, 3 );
I tried adding get_post_meta( get_the_ID(), 'key_1', true );
but looking through the codex for the post_updated
I couldn’t see if it was possible to call $post_before->$meta_key
or $post_after->$meta_key
Is there a way to do this? Or is it purely for inbuilt values?