質問編集履歴

11

コードに追記場所記載

2020/01/26 06:03

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -226,6 +226,8 @@
226
226
 
227
227
  );
228
228
 
229
+ //ここから追記しました
230
+
229
231
       $tax_query = array(
230
232
 
231
233
    array(
@@ -240,7 +242,7 @@
240
242
 
241
243
  );
242
244
 
243
-
245
+ //ここまで
244
246
 
245
247
  $query->set( 'meta_query' , $meta_query );
246
248
 
@@ -252,9 +254,7 @@
252
254
 
253
255
  $query->set( 'post_type' , 'course');
254
256
 
255
-      $query->set( 'tax_query' , $tax_query);
257
+      $query->set( 'tax_query' , $tax_query);//追記
256
-
257
-
258
258
 
259
259
  }
260
260
 

10

現状の状態にソースを修正しました。

2020/01/26 06:03

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -10,12 +10,6 @@
10
10
 
11
11
 
12
12
 
13
- ですがやりたい事はさらにカスタムタクソノミーでの一覧なのです。
14
-
15
- 上記のurlのように何かをfunctions.phpに付け足すのだろうと調べているのですが、いまだに未解決じまいです。。何かヒントをいただけないでしょうか?
16
-
17
-
18
-
19
13
  【前提条件】
20
14
 
21
15
  カスタム投稿タイプ :course
@@ -30,29 +24,17 @@
30
24
 
31
25
 
32
26
 
33
- 【やりたい事】
34
-
35
- カスタムフィールドのstart_dateの日付でカスムタクソノミーcourse_menu年別アーカイブを作りたい。
27
+ やりたい事はさらにカスタムタクソノミー一覧で
36
-
37
-
38
-
39
- この場合のurlは
40
28
 
41
29
  [homeURL]/course/course_menu/date/[yyyy]/?meta_key=start_date
42
30
 
43
-
44
-
45
- になるのかなと思いますが、どのように記述をしたら良いのかわかりません。
46
-
47
-
48
-
49
- サイトにカスタム投稿タイプを指定るまで
31
+ のような形にできないものか?とえておりま
32
+
50
-
33
+ もしくは現状の
34
+
51
- ([homeURL]/course/date/[yyyy]/?meta_key=start_dateにするまで)
35
+ [homeURL]/course/date/[yyyy]/?meta_key=start_date
52
-
36
+
53
- きたのですが、ここにどのようにカスムタクソノミーの設定すればよいのょうか?
37
+ のままも良いのですが、タクソノミーで分類できていないで、該当画面にくと全てタームの一覧となってまっています。
54
-
55
-
56
38
 
57
39
 
58
40
 
@@ -60,7 +42,7 @@
60
42
 
61
43
  ```
62
44
 
63
- //archive-course.php
45
+ //archive-course.phpで年別アーカイブへ飛ぶリンク部分
64
46
 
65
47
  <ul class="yearly-list">
66
48
 
@@ -82,8 +64,6 @@
82
64
 
83
65
  ```
84
66
 
85
- ↑ここにカスタムタクソノミーの設定も入れたいのです。
86
-
87
67
 
88
68
 
89
69
  ```
@@ -230,6 +210,8 @@
230
210
 
231
211
  if ( $query->is_year ) {
232
212
 
213
+        $taxonomy = get_queried_object();[ここが効いていない?]
214
+
233
215
  $meta_query = array(
234
216
 
235
217
  array(
@@ -244,6 +226,20 @@
244
226
 
245
227
  );
246
228
 
229
+      $tax_query = array(
230
+
231
+   array(
232
+
233
+   'taxonomy' => 'course_menu',
234
+
235
+   'field' => 'slug',
236
+
237
+  'terms' => array( $taxonomy->slug[ここが効いていない?] ),
238
+
239
+ ),
240
+
241
+ );
242
+
247
243
 
248
244
 
249
245
  $query->set( 'meta_query' , $meta_query );
@@ -256,76 +252,18 @@
256
252
 
257
253
  $query->set( 'post_type' , 'course');
258
254
 
255
+      $query->set( 'tax_query' , $tax_query);
256
+
257
+
258
+
259
259
  }
260
260
 
261
261
  }
262
262
 
263
263
  ```
264
264
 
265
- 【今んでるところまで】
265
+ SQLのソースのような部分は、知識が足りず、一回あきらめ、アドバイスいただき上記のようにtax-queryで試みたのでが、ターム一覧のようにはなりませんでした。
266
-
266
+
267
+
268
+
267
- 上記に$tax_queryを追加まし。しかしterm取得がうまくできず。んでいます。
269
+ 色々トライしたのです、どしてもうまくいかず。。なにか手がかりを探います。
268
-
269
- ちなみに'terms'の中を普通に一つ実際にあるタームスラッグ名を入れると機能していました。
270
-
271
-
272
-
273
- ```ここに言語を入力
274
-
275
- add_action( 'pre_get_posts', 'my_pre_get_posts' );
276
-
277
- function my_pre_get_posts( $query ) {
278
-
279
- if ( $query->is_year ) {
280
-
281
- $taxonomy = get_queried_object();[ここが効かない]
282
-
283
- $meta_query = array(
284
-
285
- array(
286
-
287
- 'key' => $query->get( 'meta_key' ),
288
-
289
- 'value' => $query->get( 'year'),
290
-
291
- 'compare' => 'LIKE'
292
-
293
- ),
294
-
295
- );
296
-
297
- $tax_query = array(
298
-
299
- array(
300
-
301
- 'taxonomy' => 'course_menu',
302
-
303
- 'field' => 'slug',
304
-
305
- 'terms' => array( $taxonomy->slug[ここをどうしていいかわからない] ),
306
-
307
- ),
308
-
309
- );
310
-
311
-
312
-
313
- $query->set( 'meta_query' , $meta_query );
314
-
315
- $query->set( 'year' , '' );
316
-
317
- $query->set( 'start_date' , '' );
318
-
319
- $query->set( 'meta_key' , '' );
320
-
321
- $query->set( 'post_type' , 'course');
322
-
323
- $query->set( 'tax_query' , $tax_query);
324
-
325
- }
326
-
327
- }
328
-
329
-
330
-
331
- ```

9

現状の状態を追加しました。

2020/01/26 05:38

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -262,20 +262,70 @@
262
262
 
263
263
  ```
264
264
 
265
- カスタム投稿タイプを付け足した
265
+ 【今すすんでるところまで】
266
-
266
+
267
- ```
267
+ 上記に$tax_queryを追加しました。しかしtermの取得がうまくできず。苦しんでいます。
268
-
268
+
269
- $where = "WHERE p.post_type = 'course' AND p.post_status = 'publish'";
269
+ ちなみに'terms'の中を普通に一つ実際にあるタームスラッグ名を入れると機能していました。
270
-
271
- ```
270
+
272
-
273
-
271
+
274
272
 
275
273
  ```ここに言語を入力
276
274
 
275
+ add_action( 'pre_get_posts', 'my_pre_get_posts' );
276
+
277
+ function my_pre_get_posts( $query ) {
278
+
279
+ if ( $query->is_year ) {
280
+
281
+ $taxonomy = get_queried_object();[ここが効かない]
282
+
283
+ $meta_query = array(
284
+
285
+ array(
286
+
287
+ 'key' => $query->get( 'meta_key' ),
288
+
289
+ 'value' => $query->get( 'year'),
290
+
291
+ 'compare' => 'LIKE'
292
+
293
+ ),
294
+
295
+ );
296
+
297
+ $tax_query = array(
298
+
299
+ array(
300
+
301
+ 'taxonomy' => 'course_menu',
302
+
303
+ 'field' => 'slug',
304
+
305
+ 'terms' => array( $taxonomy->slug[ここをどうしていいかわからない] ),
306
+
307
+ ),
308
+
309
+ );
310
+
311
+
312
+
313
+ $query->set( 'meta_query' , $meta_query );
314
+
315
+ $query->set( 'year' , '' );
316
+
317
+ $query->set( 'start_date' , '' );
318
+
319
+ $query->set( 'meta_key' , '' );
320
+
277
- $query->set( 'post_type' , 'course');
321
+ $query->set( 'post_type' , 'course');
322
+
278
-
323
+ $query->set( 'tax_query' , $tax_query);
324
+
325
+ }
326
+
327
+ }
328
+
329
+
330
+
279
- ```
331
+ ```
280
-
281
- このへんが変更どころなのかと思っているのですが。。

8

sqlのタグを追加しました。

2020/01/22 00:02

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
File without changes

7

質問文の訂正をしました

2020/01/20 12:51

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,18 @@
4
4
 
5
5
 
6
6
 
7
+ さらにカスタム投稿タイプでの一覧にしたかったので、下記のとおりに追加しました。
8
+
9
+ [https://www.p-nt.com/technicblog/archives/92](https://www.p-nt.com/technicblog/archives/92)
10
+
11
+
12
+
13
+ ですがやりたい事はさらにカスタムタクソノミーでの一覧なのです。
14
+
15
+ 上記のurlのように何かをfunctions.phpに付け足すのだろうと調べているのですが、いまだに未解決じまいです。。何かヒントをいただけないでしょうか?
16
+
17
+
18
+
7
19
  【前提条件】
8
20
 
9
21
  カスタム投稿タイプ :course
@@ -38,11 +50,9 @@
38
50
 
39
51
  ([homeURL]/course/date/[yyyy]/?meta_key=start_dateにするまで)
40
52
 
41
- はできたのですが、ここにどのようにカスタムタクソノミーの設定たら良いがわかりません。
53
+ はできたのですが、ここにどのようにカスタムタクソノミーの設定すればよいのでょう
42
-
43
-
44
-
45
- なにかヒントでも良いので教えていただけないでしょうか。。
54
+
55
+
46
56
 
47
57
 
48
58
 
@@ -251,3 +261,21 @@
251
261
  }
252
262
 
253
263
  ```
264
+
265
+ カスタム投稿タイプを付け足した
266
+
267
+ ```
268
+
269
+ $where = "WHERE p.post_type = 'course' AND p.post_status = 'publish'";
270
+
271
+ ```
272
+
273
+
274
+
275
+ ```ここに言語を入力
276
+
277
+ $query->set( 'post_type' , 'course');
278
+
279
+ ```
280
+
281
+ このへんが変更どころなのかと思っているのですが。。

6

説明が下手だったのでやりたい事をもっと明確に書いてみました。。

2020/01/20 01:02

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -18,11 +18,27 @@
18
18
 
19
19
 
20
20
 
21
+ 【やりたい事】
22
+
23
+ カスタムフィールドのstart_dateの日付でカスタムタクソノミーcourse_menuの年別アーカイブを作りたい。
24
+
25
+
26
+
27
+ この場合のurlは
28
+
29
+ [homeURL]/course/course_menu/date/[yyyy]/?meta_key=start_date
30
+
31
+
32
+
21
- やりたい事は、カスタムタクソノミー毎年別アーカイブのですがどのように記述をしたら良いのかわかりません。
33
+ になると思いますがどのように記述をしたら良いのかわかりません。
34
+
35
+
36
+
22
-
37
+ 参考サイトにカスタム投稿タイプを指定するまで
38
+
23
-
39
+ ([homeURL]/course/date/[yyyy]/?meta_key=start_dateにするまで)
24
-
40
+
25
- 参考サイトにカスタム投稿タイプを指定するまではできたのですが、ここにどのようにカスタムタクソノミーの設定をしたら良いかがわかりません。
41
+ はできたのですが、ここにどのようにカスタムタクソノミーの設定をしたら良いかがわかりません。
26
42
 
27
43
 
28
44
 

5

質問文の訂正をしました

2020/01/19 04:14

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -18,11 +18,11 @@
18
18
 
19
19
 
20
20
 
21
- やりたい事は、さらに下層のカスタムタクソノミー毎の年別アーカイブなのですがどのように記述をしたら良いのかわかりません。
21
+ やりたい事は、カスタムタクソノミー毎の年別アーカイブなのですがどのように記述をしたら良いのかわかりません。
22
-
23
-
24
-
22
+
23
+
24
+
25
- 参考サイトにカスタム投稿タイプを指定するまではできたのですが、これですと、アーイブ先は全てのター年別となっていまうのです
25
+ 参考サイトにカスタム投稿タイプを指定するまではできたのですが、ここにどのようにムタクソノミーの設定をしたら良かがわかりせん
26
26
 
27
27
 
28
28
 

4

ソースを追加しました。

2020/01/19 02:23

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  現在アーカイブとしてリンクされてるurl :[homeURL]/course/date/[yyyy]/?meta_key=start_date
16
16
 
17
- 使用しているテンプレートはdate.php
17
+ 使用しているテンプレートはarchive-course.php
18
18
 
19
19
 
20
20
 
@@ -32,6 +32,32 @@
32
32
 
33
33
  以下、現在のソースです。
34
34
 
35
+ ```
36
+
37
+ //archive-course.php
38
+
39
+ <ul class="yearly-list">
40
+
41
+ <?php
42
+
43
+ $taxonomy = $wp_query->get_queried_object();
44
+
45
+ my_get_year_archives( array(
46
+
47
+ 'date_field' => 'start_date',
48
+
49
+ 'post_type' => 'course',
50
+
51
+ ) );
52
+
53
+ ?>
54
+
55
+ </ul>
56
+
57
+ ```
58
+
59
+ ↑ここにカスタムタクソノミーの設定も入れたいのです。
60
+
35
61
 
36
62
 
37
63
  ```

3

参考サイトのURLを修正しました。

2020/01/19 01:41

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  以下のURLを参考に、カスタムフィールドの日付を利用してカスタム投稿ページの年別アーカイブを作成しました。
2
2
 
3
- [https://www.p-nt.com/technicblog/archives/92](https://www.p-nt.com/technicblog/archives/92)
3
+ [http://wpxtreme.jp/yearly-archive-using-custom-field-in-wordpress](http://wpxtreme.jp/yearly-archive-using-custom-field-in-wordpress)
4
4
 
5
5
 
6
6
 

2

functions.phpの中にmysql要素もありそうだったので、タグを追加しました。

2020/01/16 12:13

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
File without changes

1

いらない情報が多かった気がしたのでfunctions.phpに絞りました。

2020/01/16 12:09

投稿

M.Takeshita
M.Takeshita

スコア24

test CHANGED
File without changes
test CHANGED
@@ -14,19 +14,15 @@
14
14
 
15
15
  現在アーカイブとしてリンクされてるurl :[homeURL]/course/date/[yyyy]/?meta_key=start_date
16
16
 
17
-
18
-
19
- 上記のurlですと、使用されるテンプレートはarchive-course.phpとなり、カスタム投稿タイプの年別となってしまいます。
17
+ 使用しているテンプレートはdate.php
20
-
21
-
22
-
18
+
19
+
20
+
23
- やりたい事は、さらに下層のカスタムタクソノミー毎の年別アーカイブなのですがどのテンプレートを作成し、そのように記述をしたら良いのかわからなくなってしいました
21
+ やりたい事は、さらに下層のカスタムタクソノミー毎の年別アーカイブなのですがどのように記述をしたら良いのかわかせん
24
-
25
-
26
-
22
+
23
+
24
+
27
- function.phpの書き方変更するのか?はたまたarchive-course.php記述を変更すれば良いの
25
+ 参考サイトにカスタム投稿タイプ指定するまでできたのが、こですと、アーカイブ先は全てのタームの年別となってまうです
28
-
29
- もしくはテンプレートを追加すれば済むことなのか。。
30
26
 
31
27
 
32
28
 
@@ -34,248 +30,182 @@
34
30
 
35
31
 
36
32
 
37
- 以下、現在の機能しているソースです。
33
+ 以下、現在のソースです。
38
34
 
39
35
 
40
36
 
41
37
  ```
42
38
 
43
- //年別アーカイブへリンクする箇所のソース
44
-
45
-
46
-
47
- <ul class="yearly-list">
48
-
49
- <?php
50
-
51
- my_get_year_archives( array(
52
-
53
- 'date_field' => 'start_date'
54
-
55
- ) );
56
-
57
- ?>
58
-
59
- </ul>
39
+ //functions.php
40
+
41
+
42
+
43
+ function my_get_year_archives( $args = '' ) {
44
+
45
+ global $wpdb, $wp_locale;
46
+
47
+
48
+
49
+ $defaults = array(
50
+
51
+ 'post_type' => 'course',
52
+
53
+ 'date_field' => 'start_date',
54
+
55
+ 'format' => 'html',
56
+
57
+ 'echo' => true,
58
+
59
+ 'limit' => '',
60
+
61
+ 'before' => '',
62
+
63
+ 'after' => '',
64
+
65
+ 'show_post_count' => false,
66
+
67
+ );
68
+
69
+
70
+
71
+ $r = wp_parse_args( $args, $defaults );
72
+
73
+ extract( $r, EXTR_SKIP );
74
+
75
+
76
+
77
+ if ( '' != $limit ) {
78
+
79
+ $limit = absint( $limit );
80
+
81
+ $limit = ' LIMIT '.$limit;
82
+
83
+ }
84
+
85
+
86
+
87
+ $field = 'm.meta_value';
88
+
89
+ $select = "SELECT SUBSTRING($field,1,4) AS 'year', count(p.ID) AS posts";
90
+
91
+ $where = "WHERE p.post_type = 'course' AND p.post_status = 'publish'";
92
+
93
+ $where .= $wpdb->prepare( ' AND m.meta_key = %s', $date_field );
94
+
95
+ $join = " INNER JOIN $wpdb->postmeta AS m ON m.post_id = p.ID";
96
+
97
+
98
+
99
+ $where = apply_filters( 'getarchives_where', $where, $r );
100
+
101
+ $join = apply_filters( 'getarchives_join' , $join , $r );
102
+
103
+
104
+
105
+ $output = '';
106
+
107
+ $query = "$select FROM $wpdb->posts AS p $join $where GROUP BY SUBSTRING($field,1,4) ORDER BY $field DESC $limit";
108
+
109
+ $key = md5( $query );
110
+
111
+ $cache = wp_cache_get( 'my_get_year_archives' , 'general' );
112
+
113
+ if ( !isset( $cache[ $key ] ) ) {
114
+
115
+ $arcresults = $wpdb->get_results( $query );
116
+
117
+ $cache[ $key ] = $arcresults;
118
+
119
+ wp_cache_set( 'my_get_year_archives', $cache, 'general' );
120
+
121
+ } else {
122
+
123
+ $arcresults = $cache[ $key ];
124
+
125
+ }
126
+
127
+
128
+
129
+ if ( $arcresults ) {
130
+
131
+ $afterafter = $after;
132
+
133
+ foreach ( (array) $arcresults as $arcresult ) {
134
+
135
+ $url = add_query_arg( array( 'meta_key' => $date_field ), get_year_link( $arcresult->year ) );
136
+
137
+ $text = sprintf( '%d', $arcresult->year ).' Program Archive';
138
+
139
+ if ($show_post_count)
140
+
141
+ $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
142
+
143
+ $output .= get_archives_link( $url, $text, $format, $before, $after );
144
+
145
+ }
146
+
147
+ }
148
+
149
+
150
+
151
+ if ( $echo )
152
+
153
+ echo $output;
154
+
155
+ else
156
+
157
+ return $output;
158
+
159
+ }
160
+
161
+
162
+
163
+ add_action( 'init', 'my_init' );
164
+
165
+ function my_init() {
166
+
167
+ global $wp;
168
+
169
+ $wp->add_query_var( 'meta_key' );
170
+
171
+ }
172
+
173
+
174
+
175
+ add_action( 'pre_get_posts', 'my_pre_get_posts' );
176
+
177
+ function my_pre_get_posts( $query ) {
178
+
179
+ if ( $query->is_year ) {
180
+
181
+ $meta_query = array(
182
+
183
+ array(
184
+
185
+ 'key' => $query->get( 'meta_key' ),
186
+
187
+ 'value' => $query->get( 'year' ),
188
+
189
+ 'compare' => 'LIKE'
190
+
191
+ ),
192
+
193
+ );
194
+
195
+
196
+
197
+ $query->set( 'meta_query' , $meta_query );
198
+
199
+ $query->set( 'year' , '' );
200
+
201
+ $query->set( 'start_date' , '' );
202
+
203
+ $query->set( 'meta_key' , '' );
204
+
205
+ $query->set( 'post_type' , 'course');
206
+
207
+ }
208
+
209
+ }
60
210
 
61
211
  ```
62
-
63
-
64
-
65
- 現在カスタムフィールドの日付でソートしている状態ですが、カスタム投稿全体の年別アーカイブとなっています。
66
-
67
- やりたいのはカスタムタクソノミーの年別アーカイブなのです。。
68
-
69
- ```
70
-
71
- //archive-course.php
72
-
73
-
74
-
75
- <?php
76
-
77
- $args = array(
78
-
79
- 'post_type' => 'course',
80
-
81
- 'post_status' => 'publish',
82
-
83
- 'orderby' => 'meta_value',
84
-
85
- 'meta_key' => 'start_date',
86
-
87
- 'order' => 'DESC',
88
-
89
- );
90
-
91
- $query = new WP_Query($args);
92
-
93
- ?>
94
-
95
- <?php if($query->have_posts()): while($query->have_posts()) : $query->the_post(); ?>
96
-
97
- ループ内容省略
98
-
99
- <?php endwhile; endif; ?>
100
-
101
- <?php endif; ?>
102
-
103
- ```
104
-
105
-
106
-
107
- ```
108
-
109
- //functions.php
110
-
111
-
112
-
113
- function my_get_year_archives( $args = '' ) {
114
-
115
- global $wpdb, $wp_locale;
116
-
117
-
118
-
119
- $defaults = array(
120
-
121
- 'post_type' => 'course',
122
-
123
- 'date_field' => 'start_date',
124
-
125
- 'format' => 'html',
126
-
127
- 'echo' => true,
128
-
129
- 'limit' => '',
130
-
131
- 'before' => '',
132
-
133
- 'after' => '',
134
-
135
- 'show_post_count' => false,
136
-
137
- );
138
-
139
-
140
-
141
- $r = wp_parse_args( $args, $defaults );
142
-
143
- extract( $r, EXTR_SKIP );
144
-
145
-
146
-
147
- if ( '' != $limit ) {
148
-
149
- $limit = absint( $limit );
150
-
151
- $limit = ' LIMIT '.$limit;
152
-
153
- }
154
-
155
-
156
-
157
- $field = 'm.meta_value';
158
-
159
- $select = "SELECT SUBSTRING($field,1,4) AS 'year', count(p.ID) AS posts";
160
-
161
- $where = "WHERE p.post_type = 'course' AND p.post_status = 'publish'";
162
-
163
- $where .= $wpdb->prepare( ' AND m.meta_key = %s', $date_field );
164
-
165
- $join = " INNER JOIN $wpdb->postmeta AS m ON m.post_id = p.ID";
166
-
167
-
168
-
169
- $where = apply_filters( 'getarchives_where', $where, $r );
170
-
171
- $join = apply_filters( 'getarchives_join' , $join , $r );
172
-
173
-
174
-
175
- $output = '';
176
-
177
- $query = "$select FROM $wpdb->posts AS p $join $where GROUP BY SUBSTRING($field,1,4) ORDER BY $field DESC $limit";
178
-
179
- $key = md5( $query );
180
-
181
- $cache = wp_cache_get( 'my_get_year_archives' , 'general' );
182
-
183
- if ( !isset( $cache[ $key ] ) ) {
184
-
185
- $arcresults = $wpdb->get_results( $query );
186
-
187
- $cache[ $key ] = $arcresults;
188
-
189
- wp_cache_set( 'my_get_year_archives', $cache, 'general' );
190
-
191
- } else {
192
-
193
- $arcresults = $cache[ $key ];
194
-
195
- }
196
-
197
-
198
-
199
- if ( $arcresults ) {
200
-
201
- $afterafter = $after;
202
-
203
- foreach ( (array) $arcresults as $arcresult ) {
204
-
205
- $url = add_query_arg( array( 'meta_key' => $date_field ), get_year_link( $arcresult->year ) );
206
-
207
- $text = sprintf( '%d', $arcresult->year ).' Program Archive';
208
-
209
- if ($show_post_count)
210
-
211
- $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
212
-
213
- $output .= get_archives_link( $url, $text, $format, $before, $after );
214
-
215
- }
216
-
217
- }
218
-
219
-
220
-
221
- if ( $echo )
222
-
223
- echo $output;
224
-
225
- else
226
-
227
- return $output;
228
-
229
- }
230
-
231
-
232
-
233
- add_action( 'init', 'my_init' );
234
-
235
- function my_init() {
236
-
237
- global $wp;
238
-
239
- $wp->add_query_var( 'meta_key' );
240
-
241
- }
242
-
243
-
244
-
245
- add_action( 'pre_get_posts', 'my_pre_get_posts' );
246
-
247
- function my_pre_get_posts( $query ) {
248
-
249
- if ( $query->is_year ) {
250
-
251
- $meta_query = array(
252
-
253
- array(
254
-
255
- 'key' => $query->get( 'meta_key' ),
256
-
257
- 'value' => $query->get( 'year' ),
258
-
259
- 'compare' => 'LIKE'
260
-
261
- ),
262
-
263
- );
264
-
265
-
266
-
267
- $query->set( 'meta_query' , $meta_query );
268
-
269
- $query->set( 'year' , '' );
270
-
271
- $query->set( 'start_date' , '' );
272
-
273
- $query->set( 'meta_key' , '' );
274
-
275
- $query->set( 'post_type' , 'course');
276
-
277
- }
278
-
279
- }
280
-
281
- ```