How to use wp cron job to run a function

First of all you have to remember how WP cron works. The action will trigger when someone visits your WordPress site, if the scheduled time has passed. So if your site isn’t very crowded at 3am, the cron job won’t start exactly at 3am. (You should use real cron if you really need to run … Read more

Cancel/Stop a currently ongoing scheduled cron event?

Removing / un-scheduling obsolete cron jobs can be achieved using this code snippet. add_action(“init”, “remove_cron_job”); function remove_cron_job() { wp_clear_scheduled_hook(“my_schedule_hook”); } Change the my_schedule_hook to cron’s hook name and add the code in your theme’s function.php file.

Avoiding “Missed Schedule” errors when inserting future posts

The missed schedule warning comes form those lines: https://github.com/WordPress/WordPress/blob/f884d7973b052c3efe0901bb136b9898ece8aa39/wp-admin/includes/class-wp-posts-list-table.php#L998,L999 It should be independent on any cron event, as the warning is being displayed only in case the current UTC time – post_date_gmt > 0 – there is no other condition (except for post having the future status). In order to debug the issue, check what … Read more

How to force ‘cron_schedules’ every minute instead 1 hour?

You have the wrong period alias in your code You added your personal period in my_cron_schedules() as 61sec: $schedules[“61sec”] = array( but use it in setup_schedule() as 61sek: wp_schedule_event( current_time(‘timestamp’), ’61sek’ , ‘expire_ogl’); The other parts of the code look right.

“Missed schedule” posting bug

You don’t really need a Plugin to define these type of cronjobs in a timely manner. All you need to do is to reliably call the WordPress Cron file which is wp-cron.php The question is if your Webhost allows you to start wget without any path command or if it’s allowed to start it anyway. … Read more