Custom Field Template 日付入力項目をカレンダーから入力できるようにする方法

WordPressのCustom Field Templateで日付の入力項目をカレンダーから入力できるようにする方法をまとめました。
やりたいこと
「開催日」などの日付の入力項目をカレンダーから入力できるようにしたい

カスタムフィールドの設定

date=true でカレンダー機能が有効になる
dateFirstDayOfWeek = 1 月曜始まり
日曜始まりにする場合は、dateFirstDayOfWeek = 0 にする
初期設定では過去の日付は選択できない為、過去の日付も選択できるようにする場合は、startDateで指定の日付まで遡れるようにする
曜日付きで出力する
以下をテンプレートファイルの日付を出力したい箇所へ入力
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<time> <?php $date = post_custom("event_date"); echo date('Y.n.j', strtotime($date)); ?>(<?php $date = post_custom("event_date"); $week = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); $time = strtotime($date); $w = date("w", $time); echo $week[$w]; ?>) </time> |

yyyy-mm-dd形式で取得して、表示する時に「Y.n.j」へ変換
yyyy-mm-dd形式から曜日を取得して表示
曜日はarray(“日曜”, “月曜”, “火曜”, “水曜”, “木曜”, “金曜”, “土曜”)と取得することも可能
![MARKLEAPS[マークリープス]](https://markleaps.com/blog/wp-content/themes/mkl/images/00_logo.png)

![[WordPress] プラグイン「WP ALL Import」で既存記事を一括更新(CSV上書き)する方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import_update-500x254.jpg)
![[WordPress] CSVで記事を一括インポート-プラグイン「WP ALL Import」の使い方](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import-500x254.jpg)
![[WordPress] 記事への画像挿入方法](https://markleaps.com/blog/wp-content/uploads/2025/10/pic_manual_mainimg-500x254.png)
![[WordPress] カテゴリーとタグの違いと設定方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-category-tag-500x254.jpg)