I have a problem because I try to run my function every minute...
And there are my two codes which I tried:
function my_cron_schedules($schedules){
if(!isset($schedules["61sec"])){
$schedules["61sec"] = array(
'interval' => 61,
'display' => __('Every 61 sec'));
}
return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');
add_action('wp','setup_schedule');
function setup_schedule() {
if (!wp_next_scheduled('expire_ogl') ) {
wp_schedule_event( current_time('timestamp'), '61sek' , 'expire_ogl');
}
}
add_action( 'expire_ogl', 'expire_ogl_now' );
function expire_ogl_now() {
update_post_meta(1,'now',date());
}
I tried to do also this:
add_action('wp','setup_schedule');
function setup_schedule() {
if (!wp_next_scheduled('expire_ogl') ) {
wp_schedule_event( current_time('timestamp'), 'every_minute' , 'expire_ogl');
}
}
add_action( 'expire_ogl', 'expire_ogl_now' );
function expire_ogl_now() {
update_post_meta(1,'now',date());
}
But when I check planned schedules - I get always that it will be runed every hour (even If I set '61sec' or 'every_minute'. Can somone help me? Thank you in advance.
I have a problem because I try to run my function every minute...
And there are my two codes which I tried:
function my_cron_schedules($schedules){
if(!isset($schedules["61sec"])){
$schedules["61sec"] = array(
'interval' => 61,
'display' => __('Every 61 sec'));
}
return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');
add_action('wp','setup_schedule');
function setup_schedule() {
if (!wp_next_scheduled('expire_ogl') ) {
wp_schedule_event( current_time('timestamp'), '61sek' , 'expire_ogl');
}
}
add_action( 'expire_ogl', 'expire_ogl_now' );
function expire_ogl_now() {
update_post_meta(1,'now',date());
}
I tried to do also this:
add_action('wp','setup_schedule');
function setup_schedule() {
if (!wp_next_scheduled('expire_ogl') ) {
wp_schedule_event( current_time('timestamp'), 'every_minute' , 'expire_ogl');
}
}
add_action( 'expire_ogl', 'expire_ogl_now' );
function expire_ogl_now() {
update_post_meta(1,'now',date());
}
But when I check planned schedules - I get always that it will be runed every hour (even If I set '61sec' or 'every_minute'. Can somone help me? Thank you in advance.
Share Improve this question edited Jan 13, 2021 at 5:40 Dariusz asked Jan 13, 2021 at 5:31 DariuszDariusz 12 bronze badges 1- 2 I’m voting to close this question because it's incomplete and OP requested deletion. – rudtek Commented Jan 13, 2021 at 5:45
1 Answer
Reset to default 3You 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.