add_action( 'wp', 'my_activation' );
function my_activation() {
if( ! wp_next_scheduled( 'my_hourly_event2' ) ) {
wp_schedule_event( time(), 'hourly', 'my_hourly_event2');
}
}
// добавляем функцию к указанному хуку
add_action( 'my_hourly_event2', 'do_this_hourly' );
function do_this_hourly() {
file_put_contents(__DIR__."/log123.txt", " _!_ ", FILE_APPEND | LOCK_EX);
// делаем что-либо каждый час
$posts_sticky[] = $wpdb->get_results( $wpdb->prepare( "SELECT wp_posts.ID
FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
WHERE 1=1
AND ( ( wp_postmeta.meta_key = '_extra_featured_post' AND wp_postmeta.meta_value = '1' ) AND mt1.meta_key =
'_thumbnail_id')
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date
DESC LIMIT 0, 1000"));
file_put_contents(__DIR__."/log123.txt", " _!!!_ ", FILE_APPEND | LOCK_EX);
file_put_contents(__DIR__."/log123.txt", " _".$posts_sticky[0][0]->ID."_ ", FILE_APPEND | LOCK_EX);
//проверяю их дату
foreach ($posts_sticky[0] as $id) {
file_put_contents(__DIR__."/log123.txt", " _true_ ", FILE_APPEND | LOCK_EX);
$post_date = get_the_date( 'U', $id->ID ); //unix time
if($post_date + 86400 < current_time('timestamp', 1)) { // 1day = 86400
file_put_contents(__DIR__."/log123.txt", " _".$id->ID."_ ", FILE_APPEND | LOCK_EX);
update_post_meta( $id->ID , '_extra_featured_post', '0');
}
}
}