お世話になります。
WordPressのカスタム投稿タイプ(post_type == schedule)を利用し、イベントスケジュールのページを作りたいのですが、アーカイブページで表示するイベント開催日をカスタムフィールドでdatepickerを使って入力したところ、更新後に1970/01/01になってしまいます。
http://www.webopixel.net/wordpress/343.html#p03
こちらの記事を参考に、投稿ページにあらかじめカスタムフィールドを作ってdatepickerで日付を入れると、元々あるカスタムフィールド欄に指定通りの名前と値が追加されます。
ですが、日付を指定するカスタムフィールドの箇所が1970/01/01になってしまいます。。
以下はfunction.phpの該当部分です。
php
add_action( 'admin_init', 'schedule_date' ); function schedule_date() { add_meta_box('schedule_date_meta', 'スケジュール日時(一覧ページ掲載用)', 'date_meta_html', 'schedule'); } function date_meta_html () { global $post; $custom = get_post_custom($post->ID); //メタキーがあったら if(!empty($custom)) { $date_start = $custom["date_start"][0]; //日付だけ表示 $sche_date = date("Y.m.d D", strtotime($date_start)); } echo '<input type="hidden" name="date-nonce" id="date-nonce" value="' . wp_create_nonce( 'date-nonce' ) . '" />'; //入力フィールドの表示 ?> <style type="text/css"> #event-meta table th { text-align: left; font-weight: normal; padding-right: 10px; } </style> <div id="sche-meta"> <table> <tr> <th>年月日</th> <td><input name="sche_date" class="sche_date" id="datepicker" value="<?php if(isset ( $sche_date)) echo $sche_date; ?>" size="30" placeholder="日付を選択してください" /></td> </tr> </table> </div> <?php } add_action ('save_post', 'save_date_meta'); function save_date_meta($post_id){ global $post; if ( !wp_verify_nonce( $_POST['date-nonce'], 'date-nonce' )) { return $post_id; } if ( !current_user_can( 'edit_post', $post->ID )) { return $post_id; } $temp_date = $_POST['sche_date']; $date_start = date('Y.m.d D', strtotime($temp_date)); update_post_meta($post->ID, 'date_start', $date_start); } function meta_datepicker() { global $post_type; if( 'schedule' == $post_type || 'works' == $post_type ) { wp_enqueue_style('ui-datepicker', get_bloginfo('template_url') . '/assets/css/jquery-ui.min.css'); wp_enqueue_script('ui-datepicker', get_bloginfo('template_url') . '/assets/js/jquery-ui.min.js'); wp_enqueue_script('datepicker-ja', get_bloginfo('template_url') . '/assets/js/datepicker-ja.js'); wp_enqueue_script('datepicker', get_bloginfo('template_url') . '/assets/js/datepicker.js'); } } add_action( 'admin_print_styles-post.php', 'meta_datepicker', 1000 ); add_action( 'admin_print_styles-post-new.php', 'meta_datepicker', 1000 );
datepicker-ja.js
javascript
/* Japanese initialisation for the jQuery UI date picker plugin. */ /* Written by Kentaro SATO (kentaro@ranvis.com). */ ( function( factory ) { if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. define( [ "../widgets/datepicker" ], factory ); } else { // Browser globals factory( jQuery.datepicker ); } }( function( datepicker ) { datepicker.regional.ja = { closeText: "閉じる", prevText: "<前", nextText: "次>", currentText: "今日", monthNames: [ "1月","2月","3月","4月","5月","6月", "7月","8月","9月","10月","11月","12月" ], monthNamesShort: [ "1月","2月","3月","4月","5月","6月", "7月","8月","9月","10月","11月","12月" ], dayNames: [ "日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日" ], dayNamesShort: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], dayNamesMin: [ "日","月","火","水","木","金","土" ], weekHeader: "週", dateFormat: "yy/mm/dd", firstDay: 0, isRTL: false, showMonthAfterYear: true, yearSuffix: "年" }; datepicker.setDefaults( datepicker.regional.ja ); return datepicker.regional.ja; } ) );
datepicker.js
javascript
(function($) { $(function() { $('#datepicker').datepicker({ minDate: new Date() }); }); })(jQuery);
お分かりになる方、ご教授のほど宜しくお願い致します。
まだ回答がついていません
会員登録して回答してみよう