Need help setting up email notification for a parent post author.
post types
1. User-donor
2. Student
3. Sponsorships
4. Sponsorship updates
A logged-in user creates a sponsorship, picking a student to sponsor.
There is a Sponsorship Update Wall where the user/sponsor/donor can post messages the staff will share with the students. Also, the staff can help the student post a message to the sponsor/donor.
When an update post is made, the staff gets a email notification.
I need a way to send a notification to the sponsor/donor when and update is made.
One sponsorship (parent) has many updates (child).
Looking to set up notification email for the author of the parent post when there is a new child post.
Thanks
Hi,
Thank you for contacting us and I'd be happy to assist.
There is no built-in option available to send a form notification to the parent post's author, so this will require some customization, using the hook "cred_notification_recipients" and the function "toolset_get_related_post":
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
You'll find a good usage example for a similar case, in this thread:
https://toolset.com/forums/topic/email-notification-to-parent-post-author-when-child-form-is-submitted/
regards,
Waqar
Thanks, I tried this, added to code snippet plugin
Do I have a syntax error?
/* Notification email to parent post author
Student-Sponsor Update is name of notification I have set up (sending to a specific email addresses is working)
5010 is the form id */
add_filter('cred_notification_recipients', 'ts_cred_notification_recipient_5010', 10, 4);
function ts_cred_notification_recipient_5010($recipients, $notification, $form_id, $post_id){
if (isset($notification['name']) && 'Student-Sponsor Update' == $notification['name'] && 5010 == $form_id ){
$parent_post_id = toolset_get_related_post($post_id, 'sponsorship' );
$author_id = get_post_field ('post_author', $parent_post_id);
$post_email = get_the_author_meta( 'user_email', $author_id );
$recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$post_email, );
}
return $recipients;
}
Thanks for writing back.
To troubleshoot this, I'll need to see how the involved elements are set up in the admin area.
Can you please share temporary admin login details?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
Thank you for sharing the access details.
I tried to view Toolset components like Forms or post relationships, but, the user's role doesn't seem to allow that.
Can you please make sure that this user has the "administrator" user role?
I updated login info - part of a mulit-site install and have some menu items hidden for sub-site admins
Thank you for updating the admin access.
Reviewing the post relationships and the form "Form for Updates", I understand that you'd like to send the email notification to the parent "Sponsorships" post.
In that case, the correct relationship slug to use would be "sponsorship-update" and not "sponsorship", in the "toolset_get_related_post" function.
You'll change the following line in your code snippet from:
$parent_post_id = toolset_get_related_post($post_id, 'sponsorship' );
To:
$parent_post_id = toolset_get_related_post($post_id, 'sponsorship-update' );
My issue is resolved now. Thank you!
I knew it had to be a simple error like that.
I also found I had made a mistake on the name of the form also.