Skip Navigation

[Resolved] Email notification to parent post author when child form is submitted

This thread is resolved. Here is a description of the problem and solution.

Problem:

Get parent post author email address in filter hook "cred_notification_recipients".

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/email-notification-to-parent-post-author-when-child-form-is-submitted/#post-1653627

Relevant Documentation:

https://developer.wordpress.org/reference/functions/get_the_author_meta/

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by fedeD-3 4 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1653337

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;
}

#1653627

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/

#1653765

Thank you Luo. Now it works.