add_action('check_certification_expiry', 'check_certification_expiry'); error_log("Certification expiry check ran at " . date('Y-m-d H:i:s')); function check_certification_expiry() { $today = date('Y-m-d'); $target_date = date('Y-m-d', strtotime('+7 days')); $args = array( 'post_type' => 'certification', 'meta_query' => array( array( 'key' => 'expiry_date', 'value' => $target_date, 'compare' => '=' ) ) ); $query = new WP_Query($args); if ($query->have_posts()) { $to = 'your@email.com'; $subject = 'Certifications Expiring Soon'; $message = 'The following certifications are expiring in 7 days:'; while ($query->have_posts()) { $query->the_post(); $message .= "\n- " . get_the_title(); } wp_mail($to, $subject, $message); } wp_reset_postdata(); } add_action('check_certification_expiry', 'check_certification_expiry');
Scroll to top