teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

カレンダー上にカスタムフィールドの日付を反映させたいです。

2021/06/03 12:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,19 +1,20 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- wordpressカスタム投稿カレンダーを作成しています。
3
+ wordpressカスタム投稿を使い、カレンダーを作成しています。
4
- カレンダーは表示することはできましたが、カスタムフィールドの日付を取得してくれません。
4
+ カレンダーは表示することはできましたが、カレンダー上にカスタムフィールドの日付が反映されません。
5
+ single-event.php などのページにはカスタムフィールドの日付はYYYY年MM月DD日という形式で出力できます。
5
6
 
6
7
  カスタム投稿「event」
7
8
  Advanced Custom Fields でイベントの日付「edate」(デイトピッカー)
8
9
 
9
- single-event.php などのページにはカスタムフィールドの日付は出力されます。
10
10
 
11
11
 
12
+
12
13
  ### 該当のソースコード
13
14
  **functions.php**
14
15
  ```ここに言語を入力
15
16
  //「イベント」カレンダー
16
- function my_event_calendar($year = "", $month = "", $eventArray) {
17
+ function my_event_calendar($year = "", $monthかか "", $eventArray) {
17
18
  if(empty($year) && empty($month)) {
18
19
  $year = date("Y");
19
20
  $month = date("n");

2

カスタムフィールドの日付が取得できない点のみにしました

2021/06/03 12:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,124 +1,17 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- wordpressを利用して、カレンダーを作成していますが、
3
+ wordpressスタム投稿でカレンダーを作成しています
4
- どうしてもできずつずい前に進めませんので
4
+ カレンダーは表示することはできましたが、カスタムフィールドの日付を取得しくれません
5
- よろしくお願いいたします。
6
5
 
7
6
  カスタム投稿「event」
8
- taxonomy(カテゴリー)「event_category」
9
- カスタムフィールド「Advanced Custom Fields 」にて
10
- イベントの日付「edate」(デイトピッカー)
7
+ Advanced Custom Fields でイベントの日付「edate」(デイトピッカー)
11
- これらを利用してカレンダーを作成しましたが、カスタムフィールドの日付で出力されません。
12
8
 
13
- またカレンダーへの表示についてですが
14
- TOPページとイベントトップページの2つレンダを表示せたい
9
+ single-event.php などのページにはスタムフィルドの日付は出力れます。
15
10
 
16
- 【TOPページに表示するカレンダー】
17
- ◎前月、翌月は表示しない。
18
- ◎イベント名ではなく、カテゴリーtaxonomy「event_category」のアイコンのみを表示させて各single-event.phpにリンクさせたい
19
11
 
20
- 【イベントのトップページに表示するカレンダー】
21
- ◎前月、翌月表示はつける
22
- ◎「各カテゴリーのアイコン+イベント名」を表示させて
23
-  アイコンをクリックすると各カテゴリー一覧ページにリンク
24
-  イベント名をクリックすると各single-event.phpにリンク
25
- というふうにしたいです。
26
-
27
- カテゴリーも3つなのでどうにかtaxonomy「event_category」からそれぞれアイコンを出力させたい。
28
-
29
- ### 発生している問題・エラーメッセージ
30
- カレンダーは表示されるし、前月翌月などはリンクされるが
31
- カスタムフィールドの日付でイベントが出力されない。
32
-
33
- カテゴリーtaxonomy「event_category」を使ったアイコンの出力がわかりません。
34
- 下記カレンダー出力ページ内に26行目あたりの
35
- ```
36
- $eventCategory = get_post_meta($post->ID,'event_category',TRUE);//カテゴリー
37
- ```
38
- 上記はカスタムフィールドを使った場合だと思いますが、
39
- カスタムフィールドではなく、タクソノミーを使っています。
40
-
41
12
  ### 該当のソースコード
42
13
  **functions.php**
43
14
  ```ここに言語を入力
44
- //カスタム投稿
45
- add_action( 'init', 'create_post_type' );
46
- function create_post_type() {
47
- register_post_type(
48
- 'info',
49
- array(
50
- 'label'=> 'お知らせ',
51
- 'public' => true,
52
- 'hierarchical'=> true,
53
- 'has_archive' => true,
54
- "show_in_rest" => true,
55
- 'supports' => array(
56
- 'title',
57
- 'editor',
58
- 'thumbnail',
59
- 'excerpt',
60
- 'revisions',
61
- 'post-formats',
62
- ),
63
- )
64
- );
65
- register_taxonomy(
66
- 'info_category',
67
- 'info',
68
- array(
69
- 'label' => 'お知らせカテゴリー',
70
- 'public' => true,
71
- 'hierarchical'=> true,
72
- 'show_ui' => true,
73
- 'show_admin_column' => true,
74
- 'show_in_rest' => true,
75
- )
76
- );
77
-
78
- register_post_type(
79
- 'event',
80
- array(
81
- 'label'=> 'イベント',
82
- 'public' => true,
83
- 'hierarchical'=> true,
84
- 'has_archive' => true,
85
- "show_in_rest" => true,
86
- 'supports' => array(
87
- 'title',
88
- 'editor',
89
- 'thumbnail',
90
- 'excerpt',
91
- 'custom-fields',
92
- 'revisions',
93
- 'post-formats',
94
- ),
95
- )
96
- );
97
- register_taxonomy(
98
- 'event_category',
99
- 'event',
100
- array(
101
- 'label' => 'イベントカテゴリー',
102
- 'public' => true,
103
- 'hierarchical'=> true,
104
- 'show_ui' => true,
105
- 'show_admin_column' => true,
106
- 'show_in_rest' => true,
107
- )
108
- );
109
- register_taxonomy(
110
- 'event_tag',
111
- 'event',
112
- array(
113
- 'label' => 'イベントタグ',
114
- 'public' => true,
115
- 'show_ui' => true,
116
- 'show_admin_column' => true,
117
- 'show_in_rest' => true,
118
- )
119
- );
120
- }
121
-
122
15
  //「イベント」カレンダー
123
16
  function my_event_calendar($year = "", $month = "", $eventArray) {
124
17
  if(empty($year) && empty($month)) {
@@ -261,7 +154,7 @@
261
154
  <?php //イベントスケジュールを配列に格納
262
155
  $eventID = get_permalink();
263
156
  $eventTitle = get_the_title();
264
- $eventDate = get_post_meta($post->ID,'gdate',TRUE); //イベントの日付
157
+ $eventDate = get_post_meta($post->ID,'edate',TRUE); //イベントの日付
265
158
  $eventCategory = get_post_meta($post->ID,'event_category',TRUE);//カテゴリー
266
159
  preg_match('/\d{2}$/' , $eventDate , $matchDate);
267
160
  $eventData = $matchDate[0]."\t".$eventTitle."\t".$eventID."\t".$eventCat."\t";
@@ -296,7 +189,7 @@
296
189
  ```
297
190
 
298
191
  ### 試したこと
299
- カスタムフィールドの日付の設定
192
+ カスタムフィールドの日付の設定
300
193
  日付の表示フォーマット「Y年m月d日」
301
194
  返り値のフォーマット「Y年m月d日」や「Ymd」など
302
195
 

1

2021/06/03 09:53

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- wordpress カスタム投稿のカレンダーでカスタムフィールド日付の
1
+ wordpress カレンダーでカスタムフィールド日付の取得ができない
body CHANGED
File without changes