0

I have tried this solution but I can't get it to work Run function at specific time

Here is my example:

//this is for testing purposes
function my_cron_schedules($schedules){
if(!isset($schedules["1min"])){
    $schedules["1min"] = array(
        'interval' => 60,
        'display' => __('Once a minute'));
}

return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');

if ( ! wp_next_scheduled( 'my_scheduled_event' ) ) { wp_schedule_event( 
strtotime( '2019-01-04 19:39:00' ), '1min', 'my_scheduled_event' ); }

add_action( 'my_scheduled_event', 'update_ratings' );

function update_ratings() { 
//do some stuff
}
  • Did you initiate a request to trigger the event? WordPress cron isn't true cron- it will only run when someone loads a page on your site. – Milo Jan 5 at 3:57
  • The problem was in scheduled cron jobs. While testing I had previously set cron job for the same hook. After inspecting cron jobs I managed to delete that test schedule and now it is working. – Ante Medic Jan 5 at 9:25
0

The problem was in scheduled cron jobs. While testing I had previously set cron job for the same hook. After inspecting cron jobs I managed to delete that test schedule and now it is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.