Problem: I have a Form that creates child posts. I would like to use automatic email notifications to send a message to an email address field in the parent post, but I can't get the cred_notification_recipients API to use the correct email address.
Solution: Use the post relationships API and get_post_meta to access the parent post email address field:
add_filter('cred_notification_recipients', 'modify_recipients', 10, 4); function modify_recipients($recipients, $notification, $form_id, $post_id) { // Check notification name matches target notification if ( isset($notification['name']) && 'Www-opiskelijahaku' == $notification['name'] ) { // Add email recipient $parent_id = toolset_get_related_post( $post_id, 'opiskelijan-harjoittelupaikka-hakija' ); $emailpalautusosoite = get_post_meta($parent_id, 'wpcf-palautusosoite', true); $recipients[] = array( 'to' => 'to', 'address' => $emailpalautusosoite, 'name' => '', 'lastname' => ''); } return $recipients; }
Relevant Documentation:
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
https://developer.wordpress.org/reference/functions/get_post_meta/
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 7 replies, has 2 voices.
Last updated by 5 years, 11 months ago.
Assisted by: Christian Cox.