回答編集履歴

2

追記修正

2018/04/17 04:53

投稿

rmrmnrm
rmrmnrm

スコア139

test CHANGED
@@ -104,7 +104,7 @@
104
104
 
105
105
  foreach($taxonomys as $taxonomy):
106
106
 
107
- $tax_posts = get_posts(array('post_type' => 'area', 'taxonomy' => $taxonomy_name, 'term' => $taxonomy->slug ) );
107
+ $tax_posts = get_posts(array('post_type' => 'area', 'taxonomy' => $value, 'term' => $taxonomy->slug ) );
108
108
 
109
109
  if($tax_posts):
110
110
 

1

追記

2018/04/17 04:53

投稿

rmrmnrm
rmrmnrm

スコア139

test CHANGED
@@ -75,3 +75,53 @@
75
75
 
76
76
 
77
77
  ```
78
+
79
+
80
+
81
+ <<追記>>
82
+
83
+ すみません、質問を読み違えていました。
84
+
85
+ $taxonomy_nameを配列にしてループを回せば良いと思います。
86
+
87
+ 以下のソースではinputのnameが全てcat_area[]になりますのでその点は必要に応じて修正してください。
88
+
89
+
90
+
91
+ ```PHP
92
+
93
+ <?php
94
+
95
+ $taxonomy_name = array('area_all','taxonomy1','taxonomy2');
96
+
97
+ $args = array( 'orderby' => 'description', 'hide_empty' => false );
98
+
99
+ foreach($taxonomy_name as $value):
100
+
101
+ $taxonomys = get_terms($value,$args);
102
+
103
+ if(!is_wp_error($taxonomys) && count($taxonomys)):
104
+
105
+ foreach($taxonomys as $taxonomy):
106
+
107
+ $tax_posts = get_posts(array('post_type' => 'area', 'taxonomy' => $taxonomy_name, 'term' => $taxonomy->slug ) );
108
+
109
+ if($tax_posts):
110
+
111
+ ?>
112
+
113
+ <label class="search-label-<?php echo $taxonomy->slug; ?>"><input type="checkbox" name="cat_area[]" value="<?php echo $taxonomy->slug; ?>"><?php echo $taxonomy->name; ?></label>
114
+
115
+ <?php
116
+
117
+ endif;
118
+
119
+ endforeach;
120
+
121
+ endif;
122
+
123
+ endforeach;
124
+
125
+ ?>
126
+
127
+ ```