I have a form and notification setup. The body of the email notication includes some fields from related post types. As I learned related items are only working in a limited way in newest toolset.
1) If notifications are sendout right away when creating posts using forms, the right context is given and mail is being sent with field values from related post types.
2) If an event is used to change the status of a post and this is used as reason to trigger a mail notification (i.e. expiration), the right context is not given any more. Only items from the post itself are displayed, items from related post types are not shown.
My structure:
- My form creates a post from posttype "Checkin".
- It is set to be published upon creation. An expiration date is set and 1 hour before it is met, a notication is being send.
- The notification body includes fields from post type "Raumbuchung".
add_shortcode('related', function ($atts = []) {
// provide defaults
$atts = shortcode_atts(
array(
'id' => null,
),
$atts
);
$output = "";
if (isset($atts['id'])) {
// logic goes here to get fields from related post
// here I'm just returning the ID of the current post itself
$checkin= toolset_get_related_post( $raumbuchung_id, array( 'checkin', 'raumbuchung' ) );
$output = $atts['id'];
}
return $output;
});
Form body:
[related id="%%POST_ID%%"]
<!-- field from related post type is following -->
[types field='raumbuchung_layout' item='@raumbuchung-checkin.parent'][/types]
Hello. Thank you for contacting the Toolset support.
Can you please share problem URL and admin access details and tell me what notification you setup and as I understand you want to display the field "raumbuchung_layout" that belongs to parent post type with notification body - right?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Hi Minesh,
thanks. I also registered the shortcode and created a new post using the toolset form.
However, something seems to be not working with the shortcode.
Mail is not being send when [related id=""...] shortcode is used in mailtemplate. I tried it directly in mailbody of notification and within a content template - exactly as you have posted. In addition, when doing mailtest, still gives 500 error.
Could you please take a look again.
Many thanks
Bernhard
You should not do a mail test. As when you do mail test the libraries we used to get related posts will not be available and that is why you get the 500 error.
You should create a brand new post and set somehow to CRON run every minute and set your post also to be expired in 1-2 minutes. So you can check it frequently.
Or you can share the link from where I can create a new post and I would like to test it first.
Yes I did create new posts. No email was sent so far. When I remove the shortcode in functions.php emails are being send. So I suspect it is related to the shortcode somehow.
You may also create a brand new post by going to this URL
Site Domain + path: /wizard-raumbuchung-5/?raumid=Clara&kundeid=10097&zeitbeginn=1641829500&zeitende=1641830340&reservierungId=10100&raumbuchungid=10103&catering=
You may fill the field Expiration Date by changing URL param "zeitbeginn".
Click on button "Einplanen" to create a new post. The success message shows you the new post ID. You may then change the expiration date in the new post. Toolset Cron settings is set to run every 5 minutes, and in general mails are triggered. Time on server is UTC+1.
As you can see we removed the 'wpcf-'. Once you do that then you should create brand new post again and check if you see notification working as expected and see the custom field values in the email.
I already run a test on my test install and I can see the above code works fine to get parent ID and based on the parent ID I successfully get the fields belongs to parent and it gets displayed in my notification email.
Can you please try to give another try and try to add the above shortcode within the functions.php file instead of "Custom Code" section offered by Toolset. For now, you can remove the shortcode from custom code section and try to add it to functions.php file and give another try. Create brand new post and make sure you connected the parent which does have all field values.
When putting the code to function.php instead of custom code section in toolset, fields are displayed now when using option to send notification right on submit.
When using deferred notifications (send notification on expiration date), fields are still blank.
On my test install, that is not the case. I can see the correct parent fields are displayed with the post expiration email that is send to before XX time of post expiration.
As shared before, please make sure that you have parent custom fields filled. Otherwise you can setup a test install, a staging site where I can change the post expiration email settings and time and test there and see what happens on test installation.
The topic ‘[Closed] Show fields from related post types in form notifications email’ is closed to new replies.