Skip Navigation

[Resolved] Can I use a generic field to send notifications to multiple user ID's ?

This support ticket is created 6 years 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 20 replies, has 2 voices.

Last updated by Beda 6 years ago.

Assisted by: Beda.

Author
Posts
#1197071

Wait, there is something I did not know.

First of all, every email sent needs a "To" set, otherwise, no copy of the email can be created and used for Cc and Bcc.
That's logical, however, I completely missed this information.

The problem is, even if I set a To and a Bcc in the same notification, I still get only the To addressed email, not the Bcc or Cc.

However, my superiors were able to bring this to work and I am inquiring what I miss so to communicate it towards you and other clients following here.

Note, the erratum has been removed, because of incorrect information I added there.
I will be updating this thread here as soon I have exact steps and then, I will also require a Documentations update - it is nowhere mentioned how to use To and Bcc in Forms, to make it work, and it does not seem trivial
I personally never used Bcc and Cc in past for projects, but can confirm the issue reported is present since long, hence I believe my superiors are right and I simply miss a crucial detail - I will update you asap with this 🙂

For now, the case is that is should work, as long there is also a To (so the email can be copied).
We will see what's missing to confirm this.

#1197074

Thank you. I would have still had a TO field as well and not only blindly sending it, however that email is static and not an issue. All of my tests did include a TO field for each. Sorry if I caused some confusion there.

However, that said, I am quite content with the 25 notifications route you suggested. So far, with 10 notifications it is working flawlessly with 10 dynamic recipients and help of a few custom shortcodes.

Even if CC & BCC never end up working, I am happy with this solution. It's probably a better one in the end, tbh.

I appreciate your, and your team's efforts and ideas.

I will check out your exact steps at some point though. For anyone else reading this down the road it will helpful as well even if I stick with your multiple notifications route.

#1197075

No confusion and thanks because it confirms that I am not the only one that can't make it work.

I'll be in touch here as soon I have news.

Good that the workaround is feasible for you

#1197185

In case you cannot find the previous message, please log in to the forum and see the hidden, slightly green highlighted area, click on it to expand the private message I sent you.

#1201490

Okay, lol I made it SOOO far with this route without asking for help again but I got stuck. It was coming along beautifully.

I logged in to that site and checked it out, I think the only way it seems to work is if you know the recipients the CC & BCC ends up working, but to do it by a user ID from a generic field doesn't appear to work out. So I am happy to stick with multiple recipient fields if I get past a couple hurdles.

There were a few other elements to this where I had to make additional fields for each recipient, so 10 recipients = 10 extra fields across the board, no big deal, I got that semi-working, to something I know I can elaborate on.

Then I realized after all that, when it comes to the Views, showing a listing of all messages, that I cannot use query filters in the search & pagination area along with the query required in the top query section.

Specifically, because I cannot use the appropriate AND / OR configuration with the recipients and the custom field types filters matching a URL param (ie 'buildingname' )

So I need to show all results if X =( ( recipient1 or recipient2 or recipient3 or recipient 4.... ) AND ( buildingname LIKE urlparam ) )

But with the GUI I can only query like:

(recipient1 = x) OR (recipient2 = x) OR (recipient3 = x) OR (recipient4 = x) OR (buildingname LIKE urlparam )

If I omit the recipients in the query, the filters work beautifully, so I thought of showing only matching posts using conditional output but this was too slow and causing the website to timeout. Too heavy on the database I assume.

Bottom line is I can continue with this if I can inject a few other conditions to the query.

I have combed your documentation and forum and the best idea that seems to work is if I create a custom query in the functions.php

I have pieced together one that successfully limits the query to only show the author's own posts and figured it would adaptable to change 'author' to the 10 recipient fields.

Example with author:

add_filter( 'wpv_filter_query', 'prefix_show_only_current_author' );
function prefix_show_only_current_author( $query_args ) {
 if( $view_id == 1234 ) {
     global $current_user;
     $testuser = '240';
    $types = (array) $query_args['post_type'];
    print_r($query_args);
    if ( !is_admin() && in_array( 'quotes', $types ) ) {
        $query_args['author'] = empty( $current_user->ID ) ? -1 : $testuser;
    }
    return $query_args;
}
}

My failed attempts: ( Syntax obviously wrong I am not a coder, but hopefully you get what I am after )


add_filter( 'wpv_filter_query', 'prefix_show_only_current_author' );
function prefix_show_only_current_author( $query_args ) {
 if( $view_id == 1234 ) {
     global $current_user;
     $testuser1 = '240'; //will make these dynamic later once these fields match
     $testuser2 = '241';
     $testuser3 = '242';
    $types = (array) $query_args['post_type'];
    print_r($query_args);
    if ( !is_admin() && in_array( 'quotes', $types ) ) {
        $query_args['wpcf-recipient1'] = empty( $current_user->ID ) ? -1 : $testuser1;
        $query_args['wpcf-recipient2'] = empty( $current_user->ID ) ? -1 : $testuser2;
        $query_args['wpcf-recipient3'] = empty( $current_user->ID ) ? -1 : $testuser3;
    }
    return $query_args;
}
}

I feel like I am close but have been spinning my wheels for days and would greatly appreciate any guidance.
Thank you

New threads created by Beda and linked to this one are listed below:

https://toolset.com/forums/topic/alter-view-query-for-custom-fields-with-views-api-filters/

#1202996

I think this should be handled in a new ticket as now we are discussing how to display something, not how to send notifications in a Form.

I split your ticket into a new one and asked some details there.