回答編集履歴

1

情報の追加。

2018/02/18 09:06

投稿

kei344
kei344

スコア69625

test CHANGED
@@ -17,3 +17,69 @@
17
17
  【WordPressでカスタムタクソノミーの投稿を絞込み | Blog | 06.GRASSHOPPER】
18
18
 
19
19
  [https://ghweb.info/post-3685.html](https://ghweb.info/post-3685.html)
20
+
21
+
22
+
23
+ ---
24
+
25
+
26
+
27
+ **追記:**
28
+
29
+
30
+
31
+ こういうことかなぁ。
32
+
33
+
34
+
35
+
36
+
37
+ ```PHP
38
+
39
+ // 親を持つ場合
40
+
41
+ if ($category->parent != 0) {
42
+
43
+ $args = array(
44
+
45
+ 'post_type' => 'post',
46
+
47
+ 'post_status' => 'publish',
48
+
49
+ 'posts_per_page' => -1,
50
+
51
+ 'meta_key' => 'category',
52
+
53
+ 'meta_value' => $category->parent
54
+
55
+ );
56
+
57
+ // 親をもたない場合
58
+
59
+ } else {
60
+
61
+ $args = array(
62
+
63
+ 'post_type' => 'post',
64
+
65
+ 'post_status' => 'publish',
66
+
67
+ 'posts_per_page' => -1,
68
+
69
+ 'meta_key' => 'category',
70
+
71
+ 'meta_value' => $category->term_id
72
+
73
+ );
74
+
75
+ }
76
+
77
+ $query = new WP_Query($args);
78
+
79
+ ```
80
+
81
+
82
+
83
+ 【WP_Query | Class | WordPress Developer Resources】
84
+
85
+ [https://developer.wordpress.org/reference/classes/wp_query/](https://developer.wordpress.org/reference/classes/wp_query/)