I disabled WP cron within the wp-config.php file and set up a cron job on my server to run at the top of every hour against http://www.domain.com/wp-cron.php?doing_wp_cron
I have the following code in my functions.php file, but I never get the email when the crop job runs at the top of every hour.
I checked the database and confirm the job is in the wp_options table under "cron"
I can't figure out what I am doing wrong causing the email not to fire.
// Scheduled Action Hook
function menu_update_reminder( ) {
mail('myemail@address.com', 'Cron ran successfully', 'Cron ran successfully');
}
// Schedule Cron Job Event
function menu_update_cron() {
if ( ! wp_next_scheduled( 'menu_update_reminder' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'menu_update_reminder' );
}
}
add_action( 'wp', 'menu_update_cron' );
I ended up not having the most useful part in the code. The add_action
to actually run the code in the function once the cron job ran.
The menu_update_reminder
function was renamed to menu_update_reminder_run
// Scheduled Action Hook
function menu_update_reminder_run( ) {
mail('myemail@address.com', 'Cron ran successfully', 'Cron ran successfully');
}
add_action( 'menu_update_reminder' , 'menu_update_reminder_run' );
// Schedule Cron Job Event
function menu_update_cron() {
if ( ! wp_next_scheduled( 'menu_update_reminder' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'menu_update_reminder' );
}
}
add_action( 'wp', 'menu_update_cron' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.