Marinus Klasen

Marinus Klasen

  • Development
  • Consultancy
  • Developer Resources
  • Blog
  • Contact

March 15, 2022

Re-scheduling a cronjob in WordPress with WP-CLI

Marinus Klasen

Sometimes cronjobs are scheduled when a plugin is activated, and that time is not always the preferred time, especially when you’re running a daily event.

Using WP-CLI to list cron events

wp cron event list

Output

+------------------------------------+---------------------+-----------------------+------------+
| hook                               | next_run_gmt        | next_run_relative     | recurrence |
+------------------------------------+---------------------+-----------------------+------------+
| wp_privacy_delete_old_export_files | 2022-03-15 15:38:49 | 33 minutes 18 seconds | 1 hour     |
| wp_https_detection                 | 2022-03-15 15:38:49 | 33 minutes 18 seconds | 12 hours   |
| wp_version_check                   | 2022-03-15 15:38:49 | 33 minutes 18 seconds | 12 hours   |
| wp_update_plugins                  | 2022-03-15 15:38:49 | 33 minutes 18 seconds | 12 hours   |
| wp_update_themes                   | 2022-03-15 15:38:49 | 33 minutes 18 seconds | 12 hours   |
| recovery_mode_clean_expired_keys   | 2022-03-15 15:38:49 | 33 minutes 18 seconds | 1 day      |
| wp_scheduled_delete                | 2022-03-15 15:38:51 | 33 minutes 20 seconds | 1 day      |
| delete_expired_transients          | 2022-03-15 15:38:51 | 33 minutes 20 seconds | 1 day      |
| wp_scheduled_auto_draft_delete     | 2022-03-15 15:38:53 | 33 minutes 22 seconds | 1 day      |
| wolkloos_check_weather             | 2022-03-15 20:19:29 | 5 hours 13 minutes    | 1 day      |
| wp_site_health_scheduled_check     | 2022-03-21 15:38:49 | 6 days                | 1 week     |
+------------------------------------+---------------------+-----------------------+------------+

It’s the wolkloos_check_weather event I was looking for.

Unschedule the event

wp cron event unschedule wolkloos_check_weather

Reschedule the event with your own time

wp cron event schedule wolkloos_check_weather 06:00 daily

Output after reschedule

+------------------------------------+---------------------+----------------------+------------+
| hook                               | next_run_gmt        | next_run_relative    | recurrence |
+------------------------------------+---------------------+----------------------+------------+
| wp_privacy_delete_old_export_files | 2022-03-15 15:38:49 | 35 minutes 1 second  | 1 hour     |
| wp_https_detection                 | 2022-03-15 15:38:49 | 35 minutes 1 second  | 12 hours   |
| wp_version_check                   | 2022-03-15 15:38:49 | 35 minutes 1 second  | 12 hours   |
| wp_update_plugins                  | 2022-03-15 15:38:49 | 35 minutes 1 second  | 12 hours   |
| wp_update_themes                   | 2022-03-15 15:38:49 | 35 minutes 1 second  | 12 hours   |
| recovery_mode_clean_expired_keys   | 2022-03-15 15:38:49 | 35 minutes 1 second  | 1 day      |
| wp_scheduled_delete                | 2022-03-15 15:38:51 | 35 minutes 3 seconds | 1 day      |
| delete_expired_transients          | 2022-03-15 15:38:51 | 35 minutes 3 seconds | 1 day      |
| wp_scheduled_auto_draft_delete     | 2022-03-15 15:38:53 | 35 minutes 5 seconds | 1 day      |
| wolkloos_check_weather             | 2022-03-16 06:00:00 | 14 hours 56 minutes  | 1 day      |
| wp_site_health_scheduled_check     | 2022-03-21 15:38:49 | 6 days               | 1 week     |
+------------------------------------+---------------------+----------------------+------------+

Find more information on how WP-CLI and cron schedules work here:
https://developer.wordpress.org/cli/commands/cron/event/

How to run all cron events in WordPress via WP-CLI?

Run wp cron event run --due-now

How to run a specific cron event in WordPress via WP-CLI, regardless of it’s schedule?

Run wp cron event run your_cron_event

About Marinus Klasen

Marinus has been working in software/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge.

Marinus Klasen on Twitter

Leave a Reply Cancel reply

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

Ready to take action?

I'm looking forward to discuss your projects and goals!
Feel free to reach out using the contact details below.

Marinus Klasen

[email protected]
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • An easy way to copy code blocks from the WordPress Block EditorJune 9, 2022
  • Set a static IP for docker-compose containersMay 25, 2022
  • Justified auto width in Media Carousel Widget in ElementorMay 18, 2022
  • Using the WordPress REST APIMay 18, 2022
  • Remove all edit post links in WordPress with a simple filterMay 11, 2022

Copyright © 2022 · Marinus Klasen | Webdesign by Team Rood