Skip Navigation

[Resolved] E-Mail Alert

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

Problem:

The issue here is that the user wanted his users to be able to subscribe to a notification type. Lets say the user has a Job type and wants to notify user when they subscribe to a notification of a particular job type.

Solution:

This can be done by creating a secondary CPT for the notifications where the user can create the notification type they want for a job.

So on this notification cpt it should have attributes from the Jobs CPT that can be used to match a notification for a Job type. The notification CPT must also have an email field.

Then you can use this code below to send an email to a notification post based on a matching custom field criteria.

//Job Alarm function
add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data) {
    if ( $form_data['id'] == 67) {
        $job_type = get_post_meta($post_id, 'wpcf-position-normal',true);
        $job_stelle = (types_render_field( 'stelle-ist-geeignet-fur', array( 'id' => ''.$post_id.'') ));
        $notifications = get_posts('post_type=job-alarm');
        foreach ($notifications as $notification) {
            $email = get_post_meta($notification->ID, 'wpcf-e-mail', true);
            $notification_type = get_post_meta($notification->ID, 'wpcf-position-alarm',true);
            $notification_stelle = (types_render_field( 'stelle-ist-geeignet-fur-alarm', array( 'id' => ''.$notification->ID.'') ));
            if ( $job_type == $notification_type && count(array_intersect(explode(",",$job_stelle), explode(",",$notification_stelle))) > 0) {
                wp_mail($email, 'Dein Job Alarm: '.get_the_title($post_id), get_permalink($post_id)."HTML CODE CAN GO HERE");
            }
        }
    }
}
This support ticket is created 6 years, 3 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 61 replies, has 2 voices.

Last updated by SteffenM1628 6 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1079678

Tell us what you are trying to do?

Hey there i want to built an E-Mail Alert.
My Parent post type is Jobs. Jobs have custom fields (e.g. location: Berlin/London and contract: fulltime/part-time ) which describes the job.
Now I want a child post "E-mail Alert"! the Email alert should have the same fields like the Jobs post.

User saves a E-Mail-Alert (child) with the fields
location: Berlin
contract: fulltime

The user gets an E-mail when a new Job is published with the same attributes:
location: Berlin
contract: fulltime

Thank You and cheers

#1079716

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Stefen,

Thank you for contacting our support forum.

So these fields are only on the Parent post correct?

Please let me know.
Thanks,
Shane

#1079750

correct

#1079822

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screen Shot 2018-08-10 at 2.01.59 PM.png

Hi Steffen,

What you can do is when you are adding the field to the form you can select the parent information. See Screenshot for an example.

Please let me know if this helps.

Thanks,
Shane

#1080225

hey shane,

when i add afield to the form no options are displayed. only the shortcode is pasted in.

Could you give me please a more detailed walkthrough?

Thank you!

#1080233

Maybe i should explain in more details what i try to do:

Employers (User role A) can post Jobs (Custom post type).
Jobs have a Jobsform with multiple different fields e.g. "work".

The field "work" has lets say two options to select: "Fulltime" and "Part-time".
Allright, the employer publishes his job with tag "Fulltime".

Now i have candidates (user role b). The candidates should get notified everytime a new job is published depending on the tags the job is published with (in this case: "fulltime")

So, candidates should save Job-alerts (Email is send everytime a new job is posted). The job-alert is in a many to many relationship to the jobs.

The form of the job alert should reflect the same options like in the job form.
This means a candidate selects the tag "fulltime" and saves it. Now everytime a job is posted with the tag "fulltime" this candidate should get an E-Mail notification that a new job is posted to his query.

Its like an subscription to get notified when a new fulltime job is published.

Hope this helps further 🙂

#1081344

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Steffen,

Lets see if I understand now.

So its pretty much like this. Role A creates the Jobs, Role B can Apply or get notifications of the Job creations based on a predefined criteria in a child post that Role B creates

Correct?

Please let me know .

Thanks,
Shane

#1081345

Hey Shane,
correct!

#1081433

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Steffen,

Thanks for confirming, so I have a bit of bad news on this one as it will require some amount of custom code.

The reason is that the notifications are independent of each other, this means that the CPT that the form is creating, thats what the notification is tied to. You wouldn't be able to send Job creation notifications to persons who created the child posts.

This might be possible with custom coding but it isn't with our product out of the box.

Thanks,
Shane

#1081452

hey shane thank you,

in the meantime i found this one from 2012!
Maybe you can have a look at this if this is still possible?

https://toolset.com/forums/topic/subscription-to-custom-post-and-email-alert-to-the-subscribers-for-new-posts/

I do need this one. Maybe a notification can be triggered when a field changes or something else?

#1081503

Or maybe when they share the same taxonomies?
Is this a way to get mails triggered?

#1081643

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Steffen,

Yes this should still work because the hook remains unchained.

I'm happy such a simple solution exists 🙂

add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data) {
if (get_post_type($post_id) == 'post') {
$subscriptions = get_posts('post_type=subscription');
foreach ($subscriptions as $subscription) {
$email = get_post_meta($subscription->ID, 'wpcf-email', true);
wp_mail($email, 'New post published', get_permalink($post_id));
}
}

Would you like me to assist with setting this up ? If so could you provide me with access to the site ?

Thanks,
Shane

#1081657

Hey shane, great to hear that.

but one question before trying this out. Is this just a subscription to the post type or can i match the taxononmies or custom fields to it.
So a user fills out the subscription form and wants only get notified when the fields or taxonomies are matching with the post type. like in the subscription form select taxonomy: fulltime - the user gets only notified when the post type hast the fulltime taxonomy.

cheers

#1081666

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Steffen,

Technically it would be a subscription to the Post Type itself since the email would be fired after every post is created.

So this part of the code here

$email = get_post_meta($subscription->ID, 'wpcf-email', true);
wp_mail($email, 'New post published', get_permalink($post_id));

Gets the email of the user from the subscription CPT. I can add a line there to check if the correct criteria is being used.

Thanks,
Shane

#1081667

Hey shane,

great and thank you for being so patient with me ;-).

I will set the post types and fields up and give you a shout when i am ready. Can we check (criteria) only taxonimies or every custom field?
So it would make sense in the case of a job post to only get emails in the area the user has selected.

cheers