I have created a plugin in WordPress to sync posts from a third party API.
I have set a cron job to fetch data in every 10 minutes. If I'm logged in, cron is working, otherwise cron is not working.
I have created a plugin in WordPress to sync posts from a third party API.
I have set a cron job to fetch data in every 10 minutes. If I'm logged in, cron is working, otherwise cron is not working.
The WP Cron .. which runs when user hit website .. Thus if there are no website visits, WP Cron never runs.
Now you can use 2 solutions.
Disable WP-Cron and use real cron job and then custom real cron job
use custom interval in wp_schedule_event
add_filter( 'cron_schedules', 'myprefix_add_a_cron_schedule' );
function myprefix_add_a_cron_schedule( $schedules ) {
$schedules['sixsec'] = array(
'interval' => 21600, // Every 6 hours
'display' => __( 'Every 6 hours' ),
);
return $schedules;
}
///////Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_curl_cron_action' ) ) {
wp_schedule_event( time(), 'sixsec', 'myprefix_curl_cron_action' );
}
///Hook into that action that'll fire sixhour
add_action( 'myprefix_curl_cron_action', 'import_into_db' );
WordPress Import Cron is not working properly. If admin login, then only the crons are scheduled. This is default thing in WordPress. So you need to change your cron schedule to system task manager. This one is the possible way to run your cron without admin login.
Get the steps from following documentation URL. Configure It.