It seems like all the answers on here for this question end up being a syntax error, however I'm not seeing it here.
I'm trying to setup a daily job here that will run through all my 'vacation' posts, if the _simple_start_date (unix timestamp) is the same date as today, then run some functions to update the usermeta. The three functions I call are defined earlier in my plugin and I know work since as I am using them multiple other places to do the exact same thing I'm doing here. Only difference is that this is a scheduled event.
Since I have set this up, it has not ran once.
I am using define( 'DISABLE_WP_CRON', true );
for use with some other plugins I have that are running daily tasks. However from what I've read, that should not cause an issue with this.
Any help is of course greatly appreciated. thanks
add_action( 'wp', 'pto_setup_schedule' );
/**
* On an early action hook, check if the hook is scheduled - if not, schedule it.
*/
function pto_setup_schedule() {
if ( ! wp_next_scheduled( 'pto_daily_event' ) ) {
wp_schedule_event( time(), 'daily', 'pto_daily_event');
}
}
add_action( 'pto_daily_event', 'check_pto_request_date' );
/**
* On the scheduled action hook, run a function.
*/
function check_pto_request_date() {
$loop = new WP_Query( array( 'post_type' => 'vacation') );
while ( $loop->have_posts() ) : $loop->the_post();
$request_start_time = (get_post_meta( $post->ID, '_simple_start_date',true) );
if (date('Ymd') == date('Ymd', $request_start_time)){
$current_user = $post->post_author;
$request_date = get_post_meta( $post->ID, '_simple_start_date',true );
$request_year = date("Y",$request_date);
$time_year= date("Y");
$request_time = get_post_meta($post->ID, '_simple_total_hours', true);
$request_type = get_post_meta($post->ID, '_simple_vacation_type', true);
update_days_requested((-1 * $request_time), $request_type, $current_user);
update_days_left((-1 * $request_time), $request_type, $current_user);
update_days_used($request_time, $request_type, $current_user);
}
endwhile;
}
define('DISABLE_WP_CRON', true);
disables WP cron jobs, why do you expect that scheduled events will still be working? Where have you read thatdefine('DISABLE_WP_CRON', true);
doesn't cause issues with scheduled events? If you disable WP Cron you need to set up a cron job at server level that executes wp-cron.php script if you want to use WP scheduled events.