Problem: I would like to send a CRED notification to an email address that is stored in a custom field on the CRED post's parent post. How can I access that parent post field in the CRED notification recipients configurations?
The most flexible, preferred method today is to use the CRED API hook cred_notification_recipients to modify the "to", "cc", or "bcc" of the notification email.
Within the callback, you can figure out the parent post by calling get_post_meta on the child post, and accessing a hidden field that relates a parent post ID to the child post. The name of that field follows the format "_wpcf_belongs_" + parent post type slug + "_id". So if your parent post type slug is "event", then the postmeta key is "_wpcf_belongs_event_id" and the code is:
$parent_id = get_post_meta($post_id, '_wpcf_belongs_event_id', true);
Once you know the parent post ID, use it to call
again on the parent post to retrieve the email field value. Types fields use the prefix "wpcf-" in the postmeta table, so if your email field slug is "email-address-of-organizer" then the code would look like this:
$email_of_organizer = get_post_meta($parent_id, 'wpcf-email-address-of-organizer', true);
Now the variable $email_of_organizer contains the email address from the parent post. Use that to modify the code sample on the API documentation page to fit your needs.
Click the orange "+More" button to see a code sample.
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.
|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)