Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
No problem 🙂
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
Thanks,
Shane
Hey Shane,
here is what i did.
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?
cheers
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
This should be fine now. Just for me to adjust the code for you.
Would you mind allowing me access so that I can personalise the code for your case?
Thanks,
Shane
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi steffen,
I tried logging in with the credentials but they don't seem to work.
Could you check on them and let me know.
Thanks,
Shane
sorry found the mistake. Just try again.
PW: %uy@rfBiz8U&OD$P(IsEfh5C
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
The code should be working now.
This is the final version.
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);
$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);
if ( $job_type == $notification_type) {
wp_mail($email, 'New post published', get_permalink($post_id));
}
}
}
}
Please try and let me know if it works.
Thanks,
Shane
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!!
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
Right now its set to only when the job-alarm and the position-normal fields are the same.
However we can add more conditions to the code as well.
Thanks,
Shane
Hey shane,
your a genius!!!!! it works fine. You need to give this to your devs to build this into toolset!!!!! 😉
So i need to ad more fields. Could you do an example in the code?
cheers
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
When you say add more fields, you mean add more to the condition or add more to the actual email.
Please let me know.
Thanks,
Shane
1. i need to know how i have to extend your code to add more conditions.
So maybe you can make an example.
2. Can i style the email? and add more text? What do you mean with fields in email?
cheers
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
1. To add more conditions it would be like this.
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 :)");
Please let me know if this helps.
Thanks,
Shane
Thanks shane,
I will try to extend the code this evening.
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?
Cheers.
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Steffen,
Multi checkbox would respond differently,
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.
Thanks,
Shane
Hey shane,
this would be so great. So when it is a multi checkbox only one of the selected have to match to trigger.
I have set up one multi select to the job alarm form
<div class="form-group">
<label>Stelle ist geeignet für (Alarm)</label>
[cred_field field='stelle-ist-geeignet-fur-alarm' value='' urlparam='' output='bootstrap']
</div>
and built it in the function:
//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 = get_post_meta($post_id, 'wpcf-stelle-ist-geeignet-fur',true);
$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 = get_post_meta($notification->ID, 'wpcf-stelle-ist-geeignet-fur-alarm',true);
if ( $job_type == $notification_type || $job_stelle == $notification_stelle ) {
wp_mail($email, 'Dein Job Alarm', get_permalink($post_id));
}
}
}
can you modify it?
cheers