0

I am trying to run wp_cron event that fires based on a time range. But I can set an interval that is less than a certain period of time but not in a range. The scenario is if the $wp_cron_start is set to a time before noon, and if $wp_cron_start is greater than the current time then it can fire that day, if these conditions are not met then set the wp_cron to run next day. The problem the first condition is not working. Say for the scenario $wp_cron_start = "08:00".

$wp_cron_start = "08:00";
if ($wp_cron_start < date('12:00') && $wp_cron_start > date("H:i")) {
            if(!wp_next_scheduled('cron_hook')) {
                wp_schedule_event(strtotime($wp_cron_start), 'daily', 'cron_hook');
            }
        } else {
            $cron_date_start = date('D H:i:s', strtotime('+1 Weekday' . $this->options['bbna_morning_button_end_time']));
            wp_schedule_event(strtotime($cron_date_start), 'daily', 'cron_hook');
        }

This only sets the wp_cron for the next day. And it still does not fire.

Amen Ra
  • 2,843
  • 8
  • 47
  • 85
  • i dont think 'morning' is a valid argument? – David Sep 30 '15 at 23:22
  • I just changed it to daily – Amen Ra Sep 30 '15 at 23:29
  • 1
    it should work now, though you are schelduling a event every day, not just the next day. (btw you know its not a server cron job? it only fires if someone visits your site to trigger the event) – David Sep 30 '15 at 23:38
  • @david is right, you should also hook correctly this function, otherwise at every visit you will actually schedule a new event ... – Obmerk Kronen Oct 01 '15 at 05:24

0 Answers0