Hi, I've created a form that allows child posts to be created (draft, not published).
When a new child post is created, I'd like to send an email notification to the parent post author.
The child post is created by clicking a link to the form from the parent (the url of the page where users can submit the form looks like this one: /contacts/?parent_page_id=10858
I followed the documentation here https://toolset.com/forums/topic/populate-child-post-title-with-parent-post-title/ but it doesn't work.
I've tried with this one, but is not working..
Can you help me.
Thank you.
add_filter('cred_notification_recipients', 'ts_cred_notification_recipient_10901', 10, 4);
function ts_cred_notification_recipient_10901($recipients, $notification, $form_id, $post_id){
if (10901 == $form_id){
$parent_post_id = toolset_get_related_post($post_id, 'azienda-richiesta-di-contatto' );
$post_email = get_post_meta($parent_post_id, 'wpcf-email', true);
$recipients[] = array(
'to'=>'to',
'address'=>$post_email,
'name'=>'',
'lastname'=>''
);
}
return $recipients;
}
Hello,
The PHP codes you mentioned above is for sending email to a custom email field of parent post, in your case, you will need to change this line from:
$post_email = get_post_meta($parent_post_id, 'wpcf-email', true);
With:
$author_id = get_post_field ('post_author', $parent_post_id);
$post_email = get_the_author_meta( 'user_email', $author_id );
More help:
https://developer.wordpress.org/reference/functions/get_the_author_meta/
Thank you Luo. Now it works.