0

I'm trying to use WP Crontrol to run a cron job that executes 2 URLS:

Cron job 1: exampleurl.com - once every 2 minutes Cron job 2: exampleurl2.com - once every 24 hours

How can I right a function to do this that I can execute via the hook name using WP Crontrol?

Thanks,

1
  • If you have a question about the inner workings of a third party plugin, you have a better chance of getting an answer at its author's forum – cjbj Sep 15 '16 at 15:44
0

To answer your question, slightly incorrect. You can also use wp_schedule_event(), avoiding the need of a plugin.

0

AS said by Fleuv you can use wp_schedule_event() function to execute your code like this

add_action('my_twfours_action', 'my_twfours_action_fn');
my_twfours_action_fn (){
 //this code will execute every 24 hours
}
wp_schedule_event( time(), 'daily', 'my_twfours_action' ); //adding new cron schedule event

To create your 2 minutes filter and then scheduling a cron jo is like

function my_two_minutes_filter( $schedules ) {
    $schedules['two_minutes'] = array(
        'interval' => 120,
        'display' => __( 'Every 2 minutes' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'my_two_minutes_filter' );

then add action and shedule the event like

add_action('my_twominutes_call', 'my_twominutes_call_fn');
my_twominutes_call_fn(){
 //this code will execute every 2 minutes
}
wp_schedule_event( time(), 'two_minutes', 'my_twominutes_call' ); //adding new cron schedule event

Read more here wp_schedule_event();

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.