Skip Navigation

[Résolu] Email notification to parent post author when child form is submitted

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 4 années et 5 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par fedeD-3 Il y a 4 années et 5 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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.