WP Cron。。当用户点击网站时运行。。因此,如果没有网站访问,WP Cron将永远不会运行。
现在您可以使用两种解决方案。
Disable WP-Cron and use real cron job and then custom real cron job
https://support.hostgator.com/articles/specialized-help/technical/wordpress/how-to-replace-wordpress-cron-with-a-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\' );