将以下代码放入WordPress主题的function.php文件中,并保存:
//设定每篇文章的发布间隔
function force_time_between_posts($data, $postarr) {
global $wpdb;
if (empty($postarr['ID'])) return $data; $latest = $wpdb->get_var("
SELECT post_date
FROM {$wpdb->posts}
WHERE post_status IN('future','publish')
AND post_type = 'post'
AND ID != {$postarr['ID']}
ORDER BY post_date DESC
LIMIT 1");
$distance = 5; // 时间间隔(分钟)
$latest = strtotime($latest);
$current = strtotime($data['post_date']);
if ($latest < $current) { $diff = $current - $latest; } else { $diff = 0; } if ($diff >= 0 && $diff < ($distance * 60)) {
return false;
}else{
return $data;
}
}
add_action('wp_insert_post_data','force_time_between_posts',1,2);
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容