WordPressで00秒ぴったりに予約投稿
WPで00秒ピッタリに予約投稿。
add_action('transition_post_status', 'save_future', 1, 6);
function save_future($new_status, $old_status, $post)
{
if ($new_status === 'future' && $old_status !== 'future') {
$post_id = $post->ID;
do_action('save_post', $post_id, $post);
$post_date = $post->post_date;
$post_date = date("Y-m-d H:i:00", strtotime($post_date));
$post_date_gmt = $post->post_date_gmt;
$post_date_gmt = date("Y-m-d H:i:00", strtotime($post_date_gmt));
$post_val = array(
'ID' => $post_id,
'post_date' => $post_date,
'post_date_gmt' => $post_date_gmt,
);
wp_update_post($post_val);
}
return;
}
もし更新時間(modified_date)も必要なら $post_valに突っ込む。
※gutenbergなら動くが、classic editor入ってるとなぜか投稿失敗になる。
今日の学び
「classic editorは捨てろ。」
この記事が気に入ったらサポートをしてみませんか?