hey shane, great you understand my needs.
just tested the function.
if ( $job_type == $notification_type && count(array_intersect($job_stelle, $notification_stelle)) > 0) {
the code does not check if a match to the job exists. it just proofs if there is more than 0 attributes selected.
this is how the function works now:
e.g.
the alarm has attribute A and the job has attribute A the mail triggers. Excellent ? one is matching
the alarm has attribute A and the job has attribute A, B the mail triggers. Excellent ? at least one is matching
the alarm has attribute A and the job has attribute B the mail triggers. Not good ;-( cause nothing is matching
can this work?:
if ( $job_type == $notification_type && count(array_intersect($job_stelle == $notification_stelle)) > 0) {
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
I tried the last case here "the alarm has attribute A and the job has attribute B the mail triggers. Not good ;-( cause nothing is matching"
The email isn't being sent when the Job checkboxes and the notification checkboxes do not have intersecting selection.
As you can see i created some test jobs for my notification and none of those sends me an email.
Thanks,
Shane
yes because i just tested this ;-):
if ( $job_type == $notification_type && count(array_intersect($job_stelle == $notification_stelle)) > 0) {
Now everything is back on
if ( $job_type == $notification_type && count(array_intersect($job_stelle, $notification_stelle)) > 0) {
could you please try again and you will get mails (sometimes its up to five minutes)
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
Perhaps i'm still not understanding the logic.
This line of code will only work under this circumstance
if ( $job_type == $notification_type && count(array_intersect($job_stelle, $notification_stelle)) > 0) {
If the Job type is equal to the notification type AND at least 1 of the notifications stelle matches what is on the job. If those 2 conditions are not met then the email will not be sent.
But you're saying the email is sent when the Notification type and Job type is matching and there are no matching job and notification stelle . This is pretty much not possible to happen with this like of code because both sides must be true if the code is to work.
Thanks,
Shane
hey shane,
you are absolute right. the function does work. there is only one little problem in the last part of the function.
"If the Job type is equal to the notification type" (this part works fine/ so no problems here)
AND "at least 1 of the notifications stelle matches what is on the job". (this section is not right: it deos not check if there is a match - it only checks if one or more things are selected.
i have shot some screenshots to explain it more in detail 🙂
Hope this helps.
cheers
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
So I was able to find the issue as to why it wasn't working.
But its a little more complex that i had imagined and this is because of how the fields are stored. It will take some time for me to go through and create the final solution so you will see alot of jobs created on your site.
Thanks,
Shane
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
This may take some time as the issue that i'm having right now is that the custom checkbox uses a multidimensional array.
I need to break this array up to get out the values and rebuild it into a single dimensional array that can be compared using the default php function.
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
Could you try now.
This issue should be resolved.
Thanks,
Shane
Hey shane,
everything seems to work fine now.
Thank you soooo uch for going the extra mile with that.
Could you give me an example of adding a new mulstiselect field to the function?
Because you add same more code un the childs function.
This would be great. So i am able to extend the function to my needs.
cheers
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
You mean if you wanted to add another field ?
So as per usual you will do this.
//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.'') ));
// this is a new field
$job_stelle_new_field = (types_render_field( 'add the field slug here', 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.'') ));
//this is the new field
$notification_stelle_new_field = (types_render_field( 'add field slug here', array( 'id' => ''.$notification->ID.'') ));
if ( $job_type == $notification_type && count(array_intersect(explode(",",$job_stelle), explode(",",$notification_stelle))) > 0 $$ add your comparison here ) {
wp_mail($email, 'Dein Job Alarm: '.get_the_title($post_id), get_permalink($post_id)."HTML CODE CAN GO HERE");
}
}
}
}
Please let me know if this is clear.
Thanks,
Shane
i ask because you added more code:
// Add Shortcode
function get_custom_field( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'id' => '',
'field' => '',
),
$atts
);
$value = (types_render_field( 'stelle-ist-geeignet-fur-alarm', array( 'id' => '533') ));
$value2 = (types_render_field( 'stelle-ist-geeignet-fur', array( 'id' => '547') ));
//var_dump(array_intersect($value[0],$value2[0]));
// $test = do_shortcode("[types id='". 533 ."' field='stelle-ist-geeignet-fur-alarm' separator=', '][/types]");
// $test2 = do_shortcode("[types id='". 547 ."' field='stelle-ist-geeignet-fur' separator=', '][/types]");
// $flattern = array();
// foreach ($value as $key => $value){
// $new_key = array_keys($value);
// $flattern[] = $value[$new_key[0]];
// }
//var_dump(explode(",",$value2));
//var_dump($value);
//var_dump(array_intersect(explode(',',$value),explode(',',$value2)));
// // foreach($value as $v){
// var_dump(array_values($v));
// append$value_array .= array_values($v);
// }
// var_dump(explode(",",$test));
// var_dump(explode(",",$test2));
//var_dump($value_array);
// var_dump(array_intersect(explode(",",$test),explode(",",$test2)));
}
add_shortcode( 'get_custom_field', 'get_custom_field' );
do i have to extend this, too?
$value = (types_render_field( 'stelle-ist-geeignet-fur-alarm', array( 'id' => '533') ));
$value2 = (types_render_field( 'stelle-ist-geeignet-fur', array( 'id' => '547') ));
$value3 = (types_render_field( 'new-field-slug', array( 'id' => '548') ));
$value4 = (types_render_field( 'new-field-slug-alarm', array( 'id' => '549') ));
cheers
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
My apologies. I was actually to remove this because it was for testing purposes.
I created a shortcode to see if I could manually print out the values. I was able to and thats how I knew that the format of the checkboxes were a multidimensional array. You can actually remove it because its not needed.
Thanks,
Shane
Shane
Supporter
Idiomas:
Inglés (English )
Zona horaria:
America/Jamaica (GMT-05:00)
Hi Steffen,
If there are no further queries on this could you mark this ticket as resolved ?
Thanks,
Shane
Hey Shane,
Thank you so much for helping me out.
Some final questions:
1. can i use the custom code on other sites where i use toolset or do i habe to make some adjustments?
2. in the email we have the post titel from the job displayed. Can we also display the job alarm post title, too?
Thank you! ?