'campaign', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => 'email_schedule', 'compare' => 'EXISTS', ], ], ]); if (!$campaigns) { return; } foreach ($campaigns as $campaign) { // Get scheduled emails $schedule = get_post_meta($campaign->ID, 'email_schedule', true); if (!is_array($schedule)) { continue; } foreach ($schedule as $email) { // Check if the email is ready to be sent $send_time = strtotime($email['send_time']); if ($send_time > time()) { continue; } // Send the email RL_MailWarmer_Email_Handler::send_email($email); // Mark as sent $email['sent'] = true; } // Update the schedule update_post_meta($campaign->ID, 'email_schedule', $schedule); } } }