Skip Navigation

[Resolved] Nested shortcode in Email subject not working

This support ticket is created 4 years, 8 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by RensV5812 4 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1597827
Toolset25.PNG
Toolset26.jpg

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]"]
#1598539

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

#1601305

Hadn't heard of these placeholders before, but it works like a charm. 🙂

My issue is resolved now. Thank you!