Cron saving latests posts to json-file
// Scheduled Action Hook
function latest_vehicles_save( ) {
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 64,
'post_status' => 'publish',
'post_type'=>'vehicles'
));
foreach($recent_posts as $post) :
$permalink = get_permalink($post['ID']);
$thumbnail = get_the_post_thumbnail($post['ID'], 'full');
$title = $post['post_title'];
endforeach;
wp_reset_query();
}
add_action( 'latest_vehicles_save', 'latest_vehicles_save' );
// Schedule Cron Job Event
function latests_vehicle_cron_job() {
if ( ! wp_next_scheduled( 'latest_vehicles_save' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'latest_vehicles_save' );
}
}
add_action( 'wp', 'latests_vehicle_cron_job' );