$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp cron - Run function at a specific time of a day|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp cron - Run function at a specific time of a day

matteradmin9PV0评论

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
}

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
}
Share Improve this question asked Jan 4, 2019 at 19:55 Ante MedicAnte Medic 694 silver badges12 bronze badges 2
  • 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 Commented Jan 5, 2019 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 Commented Jan 5, 2019 at 9:25
Add a comment  | 

1 Answer 1

Reset to default 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.

Post a comment

comment list (0)

  1. No comments so far