WordPress.org

Ready to get started?Download WordPress

Forums

wp_next_scheduled and wp_schedule_event problem (1 post)

  1. Robert
    Member
    Posted 3 years ago #

    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('test@test.com', 'Test', 'This is a test.');
                    wp_mail('test2@test2.com', '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!

Topic Closed

This topic has been closed to new replies.

About this Topic