Skip Navigation

[Resolved] Fields in notification e-mail empty when using post status change trigger

This support ticket is created 4 years, 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by joostv-5 4 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1405635

I am trying to: Send an email notification when a post created using a CRED form is published. I am using a custom function to schedule this post based on a date entered in a date field. The scheduling is working fine, and an e-mail is triggered once the post is published. However, the emails are not showing any data from the configured fields.

I expected to see: A notification e-mail including the data set by the custom fields in the email (e.g. [wpv-post-title]).

Instead, I got: A notification e-mail in which all the fields are empty.

Additional info: The notification does include all fields when the initial status of post created by the form is set to 'draft', or when the trigger of the email is set to form submission. However, the post is then immediately published as the scheduling using the code below is ignored. The scheduling is a crucial part of what I'm trying to achieve.

The code used to schedule the post (this is working fine when the initial status is set to published, but just for reference):

add_action('cred_save_data', 'set_post_date_to', 100, 3);
function set_post_date_to($post_id, $form_data) {
  if( $form_data['id'] == 417 ) {
    $newDate = $_POST['set-new-date']['datetime'] . ' 08:00:00';
    $my_post = array(
      'ID'           => $post_id,
      'post_date' => $newDate,
      'post_date_gmt' => $newDate,
      'post_status' => 'future'
    );

    // Update the post into the database
    wp_update_post( $my_post );
  }
}
#1406429

Hello,

How do you setup the email notification settings in your post form?
Your custom PHP codes is setting the post as "future" post status, but Toolset Form email notification setting "When post status changes to" does not support "future" post status by default.

I suggest you try these:
Test the placeholder %%POST_ID%% in the mail content, check if it works.
If it works, you can use it to setup the field shrotcodes, for example:
[wpv-post-title item="%%POST_ID%%"]

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/

#1406653

Hi,

Thank you for your reply. I set up the email notification to trigger when the post status changes to published. The post is indeed set to "future" by the PHP code. As a result, the email is triggered when the scheduled date is reached and the post is published. This is working fine.

I have tried your suggestion to add the %%POST_ID%% placeholder. This is indeed causing shortcode output again, which is great!

However, I am also using fields defined by a post relationship (through a post reference field). E.g.: [wpv-post-link item="%%POST_ID%%@bericht-melding.parent"] These fields are still not working. Is there any way to define an ID in these shortcodes as well?

Again, these fields are showing as normal when the trigger of the email is set to send immediately after submitting the CRED form.

Thanks for your help so far!

#1406665

There isn't item="%%POST_ID%%@bericht-melding.parent" attribute, the item attribute does not support such kind of format.

However you can try with a content template, for example:
1) Create a content template "my-ct", with below codes:

Here display the post fields, you can add more fields shortcode into it.
[wpv-post-link item="@bericht-melding.parent"]

2) Display above content template in email content, like this:
[wpv-post-body item="%%POST_ID%%" view_template="my-ct" suppress_filters="true"]

More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-body

#1406937

That did the trick, thanks a lot! Just goes to show how with a bit of creativity virtually anything can be achieved with Toolset 😉

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.