Skip Navigation

[Resolved] email notification to list by view shortcode

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to send an email notification to several Users, provided by a View results.

Solution: You must use the PHP APIs to modify the recipients list based on the results of a View.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results

This support ticket is created 5 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.

Sun Mon Tue Wed Thu Fri Sat
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)

This topic contains 2 replies, has 2 voices.

Last updated by grahamA 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1327193
email-notification.jpg

Tell us what you are trying to do?
I wish to send user registration email notification to a dynamic list of user managers.
My list view creates a filtered list of user emails comma delimited.
Placing the shortcode as shown in the image attached does not work. I have also tried placing the view inside the registration form but there is no option to select it as a source for email list.
Is there any documentation that you are following?

Is there a similar example that we can see?
Please see image attached
What is the link to your site?

#1327227

Hi, unfortunately that input field isn't flexible enough to support a View as the source for email addresses. However, we do provide an API function that can be used to manipulate the email recipients list programmatically: cred_notification_recipients. You can find the documentation for this API available here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

Here's an example showing how to add a single recipient via CC:

add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
 
    // Check notification name matches target notification
    if ( isset($notification['name']) && 'Your notification name' == $notification['name'] ) {
 
        // Add a CC to log@emailaddress.com
        $recipients[] = array(
            'to'        =>  'cc',
            'address'   => 'log@emailaddress.com',
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
          
    return $recipients;
}

If you want to use the results of a View to define a group of email addresses, we have a PHP API available for that as well:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results
With this API you can loop over the results and take some action with each one, like so:

// Get the results of the View with ID equal to 40 and add the post titles to an array:
$filtered_posts = get_view_query_results( 40 );
$array = array();
foreach ( $filtered_posts as $filtered_post ) {
    $array[] = $filtered_post->post_title;
}

So you could combine these two examples to get the results of your View, and add each of those results into the recipients array. Let me know if you need additional assistance with that, I'm not sure of your PHP skill level so this is a general reference.

#1330625

My issue is resolved now. Thank you!