• I’m having trouble getting an event schedule in WordPress. I’ve followed the documentatation, but when I check the event using wp_next_scheduled it echo’s the time the event should have fired the first time.

    Here’s my code:

    $scheduledtime = wp_next_scheduled('dm_update_hook');
                $formatscheduledtime = date("F j, Y, g:i a", $scheduledtime);
    
                echo "<p>Next Update: " . $formatscheduledtime . "</p>";
                echo "<p>Current Time: " . date("F j, Y, g:i a") . "</p>";
    
                if (!wp_next_scheduled('dm_update_hook')) {
                    wp_schedule_event(time(), 'hourly', 'dm_update_hook' );
                    echo "Event Scheduled";
                }
    
                add_action( 'dm_update_hook', 'dm_update_function' ); 
    
                function dm_update_function() {
                    wp_mail('[email protected]', 'Test', 'This is a test.');
                    wp_mail('[email protected]', 'Testing', 'Test 2.');
                }

    Output:

    Next Update: May 17, 2011, 9:02 pm
    Current Time: May 17, 2011, 10:19 pm

    Notice how the Next Update is previous to the current time. The emails are never sent, even on first run. Any ideas what I’m doing wrong? Thanks!

  • The topic ‘wp_next_scheduled and wp_schedule_event problem’ is closed to new replies.