Skip Navigation

[Resolved] Email Notifications to Author of Parent Post

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

Problem:
When using the cred_notification_recipients hook to send a notification to the author of a parent post when a child post is created, what is the correct way to get the ID of the parent post?

Solution:
This changed with Types 3, which no longer stores the parent post ID on the child post.

You would get the parent post ID using the toolset_get_related_post function of the new API.

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This support ticket is created 6 years, 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by julieP 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#908680

In the days of CRED forms, this hook worked to send an email to the author of the parent post when a child post was created:-

add_filter('cred_notification_recipients', 'ts_cred_notification_recipient_428', 10, 4);
function ts_cred_notification_recipient_428($recipients, $notification, $form_id, $post_id){

	 // This is the Review_Listing_Create form ID     
    if (428 == $form_id){
        $parent_slug = "parentpost";
        $field_slug = '_wpcf_belongs_' . $parent_slug . '_id';
         
        $parent_post_id = get_post_meta($post_id, $field_slug, true);
        $post_email = get_post_meta($parent_post_id, 'wpcf-email-address-parentpost', true);
         
        $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$post_email );
    }
    return $recipients;
}

How do we implement this in the new world of Toolset forms?

#908729

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Julie

See my recent answer to your other question about whether you are using existing forms or creating new forms and need to replicate this functionality.

The answer is essentially the same, that in place of the get_post_meta call for the _wpcf_belongs_parent-slug_id field, you need to get the parent ID using the toolset_get_related_post method of the new relationships API:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

If you need help with the specifics of the code, let me know.

#908801

Hi Nigel

Thanks for this; I have additional queries but will add them to my other post (https://toolset.com/forums/topic/populate-child-post-title-with-parent-post-title/)