【发布时间】:2014-12-09 18:26:18
【问题描述】:
---已解决:代码如图所示---
我有这段我认为应该可以工作的代码,但是唉......
如果有人可以偷看一下,看看是否有明显的东西。我查看了很多关于 wordpress codex 的资源,但是我已经尝试了所有我能想到的。
// expired_post_delete hook fires when the Cron is executed
add_action( 'expired_post_delete', 'delete_expired_posts' );
// This function will run once the 'expired_post_delete' is called
function delete_expired_posts() {
$todays_date = current_time('mysql');
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'date',
'meta_query' => array(
array(
'key' => 'date',
'value' => $todays_date,
'type' => 'DATE',
'compare' => '<'
)
)
);
$posts = new WP_Query( $args );
// The Loop
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
wp_delete_post(get_the_ID());
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
}
// Add function to register event to WordPress init
add_action( 'init', 'register_daily_post_delete_event');
// Function which will register the event
function register_daily_post_delete_event() {
// Make sure this event hasn't been scheduled
if( !wp_next_scheduled( 'expired_post_delete' ) ) {
// Schedule the event
wp_schedule_event( time(), 'daily', 'expired_post_delete' );
}
}
【问题讨论】:
-
你试过
'value' => $todays_date(不带引号)吗? -
做了那个更新,还是没有生成,非常感谢!
标签: date custom-fields wordpress