Reputation: 1
Can someone help me solve this problem. I'm newbie in php coding
I need to run this URL twice a day via wordpress function.php https://sample.com/wp-admin/admin-ajax.php?action=run_scrapper
I used this codes but it's not working.
register_activation_hook(__FILE__, 'my_schedule');
add_action('execute_scrapper', 'do_this_daily');
function my_schedule() {
$timestamp = wp_schedule_event($timestamp, 'twicedaily', 'execute_scrapper');
}
function do_this_daily() {
wp_remote_get( 'https://sample.com/wp-admin/admin-ajax.php?action=run_scrapper', $args);
}
Upvotes: 0
Views: 699
Reputation: 1689
Wordpress is not running as a background process so in order to use wordpress schedules you would need to set a cron job on your server which will trigger your wordpress site every minute or so and then wordpress will run your scheduled function twice per day.
If you are not performing wordpress related task, you could just set a cron job to trigger the url you need. If you are using a shared hosting, most probably there is a an option to set a cron job. If you are running a VPS, then you would need to set a cron job by editing crontab.
Upvotes: 2