I still cannot get this to work especially getting the toolset custom field wpcf-contract-end-date to display.
I've tried to run the wp_user_query on its own but it does not display the proper user profiles that have the wpcf-contract-end-date set
This is my latest version. I've tried to put things into the order you suggested originally but not having any luck. Do I have the code in the proper order?
// Add a new notification event type and then check whether a specific condition is met. If it is, return the slug that will be used for your custom notification event type.
add_filter( 'cred_notification_event_type', 'my_custom_event_type', 99, 4);
function my_custom_event_type($notification_type, $form_id){
if( $form_id == '3857' ) //or 3843
//query to see if contract date is two weeks from today
// Create cron job
wp_schedule_event( time(), 'twicedaily', 'contractend_cron_hook' );
if ( ! wp_next_scheduled( 'contactend_cron_hook' ) ) {
// WP_User_Query arguments
$before_date = date("U", strtotime("+2 week"));
$args = array(
'role' => 'member',
'order' => 'ASC',
'orderby' => 'id',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'wpcf-contact-end-date',
'value' => $before_date,
'compare' => '<',
'type' => 'DATE',
),
),
);
// The User Query
$user_contract_query = new WP_User_Query( $args );
// The User Loop
if ( ! empty( $user_contract_query->results ) ) {
foreach ( $user_contract_query->results as $user ) {
wp_mail( 'wordpress@myaddress.dd', 'The Notification subject', 'The Notification message'); // do something
}
} else {
echo(' Nothing to do'); // no users found
}
}
// Return a slug for your custom notification event type. This can be anything, but must be unique.
return 'custom_notification_event_type';
}
// End of new notification event type