wp_next_scheduled

Home » Functions » wp_next_scheduled

Function Name: wp_next_scheduled

The wp_next_scheduled function is a WordPress function that is used to get the time of the next scheduled event. This function can be used to check when an event is scheduled to occur, and can be useful in determining when to schedule other events.

The wp_next_scheduled function takes two parameters: the name of the event, and an optional timestamp to base the calculation on. If no timestamp is provided, the current time is used.

This function returns the Unix timestamp of the next scheduled occurrence of the event, or false if the event is not scheduled.

Example Usage:

Let’s say we want to schedule a custom event called my_custom_event to occur every 24 hours starting from tomorrow at 9am. We can use the following code to do so:

// Set the initial time to tomorrow at 9am
$initial_time = strtotime('tomorrow 9am');

// Schedule the event to occur every 24 hours
wp_schedule_event($initial_time, 'daily', 'my_custom_event');

// Get the timestamp of the next occurrence of the event
$next_scheduled_time = wp_next_scheduled('my_custom_event');

// Output the timestamp in a human-readable format
echo 'The next occurrence of my_custom_event is scheduled for ' . date('Y-m-d H:i:s', $next_scheduled_time);

This code will output the timestamp of the next occurrence of the event in a human-readable format.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.