Hi guys,
I've set up an email notification after a cred form is submitted and I'm trying to display a nested shortcode in the email subject. The form creates a new message in the private messaging system and the field I want rendered is the post name of the initial post where the messaged was created from. It renders in the email body just fine, but not in the subject. Any idea what causes that and if I can rewrite the code to get the expected result?
[wpv-post-title item="[types field='initial-post-id' format='FIELD_VALUE'][/types]"]
- or -
[wpv-post-title item="[types field='initial-post-id' format='FIELD_VALUE'][/types]"]
Hi,
Thank you for contacting us and I'd be happy to assist.
When the output from complex or nested shortcodes is involved in form notifications, it is better to use custom placeholders:
https://toolset.com/documentation/user-guides/front-end-forms/how-to-use-custom-placeholders-in-cred-notifications/
For example:
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification', 10, 1);
add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);
function custom_generic_field_notification( $defaultPlaceHolders ) {
$initial_post_id = $_REQUEST['wpcf-initial-post-id'];
if (!empty($initial_post_id)) {
$initial_post_title = get_the_title($initial_post_id);
$newPlaceHolders = array(
'%%INITIAL_POST%%' => $initial_post_title
);
}
return array_merge($defaultPlaceHolders, $newPlaceHolders );
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
After that, you'll be able to use %%INITIAL_POST%% directly in the notification subject and the body and it will be replaced with the title of the post, whose ID will be in the field with slug "initial-post-id".
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Hadn't heard of these placeholders before, but it works like a charm. 🙂
My issue is resolved now. Thank you!