Customizing WordPress Cron – event at a specific time

You block advertising

Please disable ad blocker

Read more

I often find articles about cron in WordPress, which describe how to configure the task to run at intervals from the current time, but there is almost no information on how to set the event at a specific time with the necessary interval.

Example with an event from the current time:

if( !wp_next_scheduled('send_email_event' ) )
   wp_schedule_event( time(), 'daily', 'send_email_event' );
add_action( 'send_email_event', 'event_send', 10, 3 );

And now an event at a specific time with a function strtotime():

if( !wp_next_scheduled('send_email_event' ) )
   wp_schedule_event( strtotime('18:00:00'), 'daily', 'send_email_event' );
add_action( 'send_email_event', 'event_send', 10, 3 );

As you can see, such an event will be run every day at 18:00.

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

Comments (0)
Leave a Reply

Your email address will not be published. Required fields are marked *