I have a custom post type immobile
with some custom fields created with Toolset Types.
I need to send and email with the title and a custom field when a new immobile
is saved as a draft or it's published.
I managed to do almost everthing. My code is like this:
add_action( 'auto-draft_to_draft', 'my_send_email', 99 );
add_action( 'auto-draft_to_publish', 'my_send_email', 99 );
add_action( 'draft_to_publish', 'my_send_email', 99 );
function my_send_email( $post ) {
if ( $post->post_type == 'immobile' ) {
wp_mail(
'email@example.com',
'New immobile saved as ' . $post->post_status,
'Title: ' . $post->post_title . '. Ref: ' . get_post_meta( $post->ID, 'wpcf-reference', true ),
array('Content-Type: text/html; charset=UTF-8')
);
}
}
Unfortunately my custom field is not showing in the email, probably because It get saved after the hook I'm using.
The perfect solution would be a hook wich:
- Is fired after the post meta are saved
- Allow me to check the post_status of the post before it was saved.
I tried the hook post updated
but I got the same result: the custom field does not show up.
Which hook could I use? Or I should try a totally different approach?