Hi I have a url which imports data from csv to database on wordpress.I want this to run every 2 minutes .Is tried a plugin for this cron job scheduer but this did not work. How can I write a action script function make this possibe.Please help
Asked
Active
Viewed 5,127 times
1 Answers
3
You can do the following
First you need to add the 2m interval to the schedule
add_filter('cron_schedules', 'my_schedules');
function my_schedules($schedules)
{
$schedules['once_every_2m'] = array('interval' => 120, 'display' => 'Once every 2 minutes');
return $schedules;
}
Then you add your job using newly created interval
if (!wp_next_scheduled('name_of_your_job'))
{
wp_schedule_event(1481799444, 'once_every_2m', 'name_of_your_job');
}
add_action('name_of_your_job', 'function_that_should_be_executed');
function function_that_should_be_executed()
{
//do what you need to do
}
Also, keep in mind, due to how WP cron works, it might be in accurate with timing. Docs

Igor Yavych
- 4,166
- 3
- 21
- 42
-
1@Melvin you can do whatever you need within the function `function_that_should_be_executed` – Igor Yavych Dec 15 '16 at 11:10
-
Can you give me an example code please . I am blank – Melvin Dec 15 '16 at 11:11
-
1I already gave you an full code. I can't and won't write whole function since I have no idea what you want to do every 2 minutes. You should be able to do what you need within the function. – Igor Yavych Dec 15 '16 at 11:31
-
i want to hit a url every 2 minutes – Melvin Dec 15 '16 at 11:33
-
2So what's stopping you? Write code to do that within `function_that_should_be_executed` and you'll be good – Igor Yavych Dec 15 '16 at 11:33
-
1The this is a very good opportunity to learn, don't you think? This resource is meant to help you learn, not to ask someone to do your job for you. – Igor Yavych Dec 15 '16 at 11:43
-
You could use it if it does what you need, yes – Igor Yavych Dec 15 '16 at 13:20