Your code for scheduling event isn’t correct, here is the correct one:
function hits_set_zero_schedule() {
if ( ! wp_next_scheduled( 'hits_set_to_zero') )
wp_schedule_event( time(), 'daily', 'hits_set_zero' );
}
add_action( 'wp', 'hits_set_zero_schedule' );
function hits_set_zero_func() {
delete_post_meta( $post_id, 'post_views_count', true );
}
add_action( 'hits_set_zero', 'hits_set_zero_func' );
Also, you can define intervals otherwise than daily
by adding a little snippet to your code:
add_filter( 'cron_schedules', 'my_custom_schedule' );
function my_custom_schedule( $schedules ) {
$schedules[ 'five_minutes' ] = array(
'interval' => 5 * 60,
'display' => 'Once five minutes'
);
return $schedules;
}
You can change the interval
element in the $schedules
element, it’s in seconds.