Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.
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.
This support ticket is created vor 6 Jahren, 3 Monaten. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Yes we can critieria's based on a custom field or taxonomy. In this case I would recommend using a custom field since you can have Fulltime , Part Time or Both
1. Created a custom post type "jobs" with a form and a field called "positions" (slug: position-normal) to match with the job alarms field
2. Created a custom post type called "job alarms" with a form and an email-field (to collect the Email) and a field called "position (alarm)" (slug: position-alarm) with the identical select options like in the job post.
So whats the next steps to take? In the old post from 2012 is something mentioned to create another CRED for sending the mail? is this an empty CRED only with an E-Mail notification?
Wow, great!
Thank you shane i will check the code this evening.
Could you just give me an example if i want to add more fields to the code?
And when there ate more than one field in the function. Will the email only be send when all fields are matching or just one of them?
Would prefer that all fields have to match.
I give you a shout when i have tested the function.
Again thanks a lot!!! ??
Cheers!!
add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data) {
if ( $form_data['id'] == 67) {
// Add another line like this below changing the $job_type variable name to another name and change wpcf-position-normal to your custom field slug keeping the wpcf- prefix.
$job_type = get_post_meta($post_id, 'wpcf-position-normal',true);
// Example
// $job_city = get_post_meta($post_id, 'wpcf-city',true);
$notifications = get_posts('post_type=job-alarm');
foreach ($notifications as $notification) {
$email = get_post_meta($notification->ID, 'wpcf-e-mail', true);
// You will need to do the same for the line below as I did with Job city, to get the notification city to check if it matches.
$notification_type = get_post_meta($notification->ID, 'wpcf-position-alarm',true);
// Then you can add the condition for the job_city in the if statement below. Example
if ( $job_type == $notification_type || $job_city == $notification_city ) {
wp_mail($email, 'New post published', get_permalink($post_id));
}
}
}
}
2. For the customization the mail you will need to edit the wp_mail() function.
Example.
wp_mail($email, 'New post published', get_permalink($post_id)." You Can write anything you want here :)");
Do you know how this function reacts on a multi checkbox field? Do the fields have to match exactly, too?
Or is it possible for multi checkboxes only have to match one of the selected possibilities to trigger the mail. This is what i would prefer and maybe we can add this?
I would need to check how the multi field is returned but I should be able to accomplish this with one of the php functions by comparing the arrays to see if they are the same.