0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AFCのデイトピッカーを公開期限として使う

Last updated at Posted at 2023-07-07

カスタムフィールドに入力した日時と現在の日時を比較して
期限が来たら自動で公開終了〜とかしたいとき。

page-template.php
//カスタムフィールドの日付を取得(AFC)
$due_date = get_field('due_date');
 
//日付が空は無期限とする
if(!empty($due_date)) {
    $now_date = new DateTime(wp_date('Y-m-d G:i:s'));
    $close_date = new DateTime($due_date);

    if($close_date < $now_date){
        wp_redirect(esc_url(home_url('/closed/')));
        exit;
    }
}

wp_date()を使わないと日時が9時間ずれるみたい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?