回答編集履歴
2
追記
test
CHANGED
@@ -87,3 +87,63 @@
|
|
87
87
|
var_dump($posts);
|
88
88
|
|
89
89
|
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
----
|
94
|
+
|
95
|
+
**(追記) 複数の子タクソノミーがある場合**
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```php
|
102
|
+
|
103
|
+
$child_term_ids = array();
|
104
|
+
|
105
|
+
foreach ($child_taxs as $child_tax) :
|
106
|
+
|
107
|
+
$child_term_ids[] = $child_tax->term_id;
|
108
|
+
|
109
|
+
endforeach;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
$posts = get_posts(
|
114
|
+
|
115
|
+
array(
|
116
|
+
|
117
|
+
'tax_query' => array(
|
118
|
+
|
119
|
+
array(
|
120
|
+
|
121
|
+
'include_children' => false,
|
122
|
+
|
123
|
+
'taxonomy' => 'area',
|
124
|
+
|
125
|
+
'field' => 'term_id',
|
126
|
+
|
127
|
+
'terms' => $parent_tax->term_id,
|
128
|
+
|
129
|
+
),
|
130
|
+
|
131
|
+
array(
|
132
|
+
|
133
|
+
'taxonomy' => 'area',
|
134
|
+
|
135
|
+
'field' => 'term_id',
|
136
|
+
|
137
|
+
'terms' => $child_term_ids,
|
138
|
+
|
139
|
+
'operator' => 'NOT IN'
|
140
|
+
|
141
|
+
)
|
142
|
+
|
143
|
+
)
|
144
|
+
|
145
|
+
)
|
146
|
+
|
147
|
+
);
|
148
|
+
|
149
|
+
```
|
1
追記
test
CHANGED
@@ -33,3 +33,57 @@
|
|
33
33
|
var_dump($posts);
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
----
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
**(追記)タクソノミーを除外する例**
|
44
|
+
|
45
|
+
以下のようにtax_queryを追加してNOT INで、除外したいタクソノミーを指定すれば除外できます
|
46
|
+
|
47
|
+
以下の例ではterm_idが6を除外しています。
|
48
|
+
|
49
|
+
```php
|
50
|
+
|
51
|
+
$posts = get_posts(
|
52
|
+
|
53
|
+
array(
|
54
|
+
|
55
|
+
'tax_query' => array(
|
56
|
+
|
57
|
+
array(
|
58
|
+
|
59
|
+
'include_children' => false,
|
60
|
+
|
61
|
+
'taxonomy' => 'area',
|
62
|
+
|
63
|
+
'field' => 'term_id',
|
64
|
+
|
65
|
+
'terms' => 4,
|
66
|
+
|
67
|
+
),
|
68
|
+
|
69
|
+
array(
|
70
|
+
|
71
|
+
'taxonomy' => 'area',
|
72
|
+
|
73
|
+
'field' => 'term_id',
|
74
|
+
|
75
|
+
'terms' => 6,
|
76
|
+
|
77
|
+
'operator' => 'NOT IN'
|
78
|
+
|
79
|
+
)
|
80
|
+
|
81
|
+
)
|
82
|
+
|
83
|
+
)
|
84
|
+
|
85
|
+
);
|
86
|
+
|
87
|
+
var_dump($posts);
|
88
|
+
|
89
|
+
```
|