質問編集履歴
2
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,53 +24,81 @@
|
|
24
24
|
|
25
25
|
```php
|
26
26
|
|
27
|
+
<?php
|
28
|
+
|
29
|
+
$taxonomy_slug = 'areatag';
|
30
|
+
|
31
|
+
$post_type_slug = 'area';
|
32
|
+
|
33
|
+
// ターム情報を取得
|
34
|
+
|
35
|
+
$post_terms = wp_get_object_terms($post->ID, $taxonomy_slug);
|
36
|
+
|
37
|
+
if( $post_terms && !is_wp_error($post_terms)) {
|
38
|
+
|
39
|
+
$terms_slug = array();
|
40
|
+
|
41
|
+
foreach( $post_terms as $value ){
|
42
|
+
|
43
|
+
$terms_slug[] = $value->slug;
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
$args = array(
|
50
|
+
|
51
|
+
'post_type' => $post_type_slug,
|
52
|
+
|
53
|
+
'posts_per_page' => 5,
|
54
|
+
|
55
|
+
'post__not_in' => array($post->ID), // 現在の投稿を除外
|
56
|
+
|
57
|
+
'tax_query' => array(
|
58
|
+
|
59
|
+
array(
|
60
|
+
|
61
|
+
'taxonomy' => $taxonomy_slug,
|
62
|
+
|
63
|
+
'field' => 'slug', // スラッグに一致するタームを返す
|
64
|
+
|
65
|
+
'terms' => $terms_slug[2] // タームの配列を指定
|
66
|
+
|
67
|
+
)
|
68
|
+
|
69
|
+
)
|
70
|
+
|
71
|
+
);
|
72
|
+
|
73
|
+
$the_query = new WP_Query($args); if($the_query->have_posts()):
|
74
|
+
|
75
|
+
?>
|
76
|
+
|
27
|
-
<!-- 同じエリアの
|
77
|
+
<!-- 同じエリアの記事 -->
|
28
78
|
|
29
79
|
<div class="d-flex justify-content-between mb-2 mt-3 mt-md-0 bg-black pl-3 py-2">
|
30
80
|
|
31
|
-
<p class="font-weight-bold mb-0 text-white">同じエリアの
|
81
|
+
<p class="font-weight-bold mb-0 text-white">同じエリアの記事</p>
|
32
82
|
|
33
83
|
<p class="h8 mb-0 pr-4 pt-1">
|
34
84
|
|
85
|
+
<?php $terms = get_the_terms( $post->ID, $taxonomy_slug); ?>
|
86
|
+
|
87
|
+
<?php foreach( $post_terms as $term ): ?>
|
88
|
+
|
35
|
-
|
89
|
+
<a href="<?php echo get_term_link( $term->term_id, $taxonomy_slug ); ?>" class="text-white <?php echo $term->slug ?>">
|
90
|
+
|
91
|
+
<?php echo 'もっと見る' ?>
|
92
|
+
|
93
|
+
</a>
|
94
|
+
|
95
|
+
<?php endforeach; ?>
|
36
96
|
|
37
97
|
</p>
|
38
98
|
|
39
99
|
</div>
|
40
100
|
|
41
|
-
<?php
|
42
|
-
|
43
|
-
$taxonomy_slug = 'areatag';
|
44
|
-
|
45
|
-
$post_type_slug = 'area';
|
46
|
-
|
47
|
-
$terms = wp_get_object_terms($post->ID, $taxonomy_slug);
|
48
|
-
|
49
|
-
foreach ( $terms as $value ) {
|
50
|
-
|
51
|
-
echo '<h2>'.esc_html($value->name).'</h2>';
|
52
|
-
|
53
|
-
$term_slug = $value->slug;
|
54
|
-
|
55
|
-
$args = array(
|
56
|
-
|
57
|
-
'post_type' => $post_type_slug,
|
58
|
-
|
59
|
-
$taxonomy_slug => $term_slug ,
|
60
|
-
|
61
|
-
'posts_per_page' => 5,
|
62
|
-
|
63
|
-
'post_status' => 'publish'
|
64
|
-
|
65
|
-
);
|
66
|
-
|
67
|
-
$myquery = new WP_Query( $args );
|
68
|
-
|
69
|
-
?>
|
70
|
-
|
71
|
-
<?php if ( $myquery->have_posts()): ?>
|
72
|
-
|
73
|
-
<?php while($
|
101
|
+
<?php while ($the_query->have_posts()): $the_query->the_post(); ?>
|
74
102
|
|
75
103
|
<div class="d-flex">
|
76
104
|
|
@@ -104,10 +132,8 @@
|
|
104
132
|
|
105
133
|
<?php endwhile; ?>
|
106
134
|
|
135
|
+
<?php wp_reset_postdata(); ?>
|
136
|
+
|
107
137
|
<?php endif; ?>
|
108
138
|
|
109
|
-
<?php wp_reset_postdata(); ?>
|
110
|
-
|
111
|
-
<?php } // ループの終了 ?>
|
112
|
-
|
113
139
|
```
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
以下の通り、wp_get_object_terms関数を使って、タクソノミー情報を取得し、一覧表示しようとしましたが、
|
15
|
+
以下の通り、wp_get_object_terms関数を使って、タクソノミー情報を取得し、一覧表示しようとしましたが、特定のタームを絞り込むことができず、表示することができませんでした。
|
16
16
|
|
17
17
|
|
18
18
|
|
@@ -24,17 +24,15 @@
|
|
24
24
|
|
25
25
|
```php
|
26
26
|
|
27
|
-
<
|
27
|
+
<!-- 同じエリアの物件 -->
|
28
28
|
|
29
|
-
|
29
|
+
<div class="d-flex justify-content-between mb-2 mt-3 mt-md-0 bg-black pl-3 py-2">
|
30
30
|
|
31
|
-
<div class="d-flex justify-content-between mb-2 mt-3 bg-black pl-3 py-2">
|
32
|
-
|
33
|
-
<p class="font-weight-bold mb-0 text-white">
|
31
|
+
<p class="font-weight-bold mb-0 text-white">同じエリアの物件</p>
|
34
32
|
|
35
33
|
<p class="h8 mb-0 pr-4 pt-1">
|
36
34
|
|
37
|
-
<a href=
|
35
|
+
<a href="/investcat/all" class="text-white">もっと見る</a>
|
38
36
|
|
39
37
|
</p>
|
40
38
|
|
@@ -42,23 +40,37 @@
|
|
42
40
|
|
43
41
|
<?php
|
44
42
|
|
45
|
-
|
43
|
+
$taxonomy_slug = 'areatag';
|
46
44
|
|
47
|
-
|
45
|
+
$post_type_slug = 'area';
|
48
46
|
|
49
|
-
|
47
|
+
$terms = wp_get_object_terms($post->ID, $taxonomy_slug);
|
50
48
|
|
51
|
-
)
|
49
|
+
foreach ( $terms as $value ) {
|
52
50
|
|
53
|
-
|
51
|
+
echo '<h2>'.esc_html($value->name).'</h2>';
|
54
52
|
|
55
|
-
|
53
|
+
$term_slug = $value->slug;
|
56
54
|
|
55
|
+
$args = array(
|
56
|
+
|
57
|
+
'post_type' => $post_type_slug,
|
58
|
+
|
59
|
+
$taxonomy_slug => $term_slug ,
|
60
|
+
|
61
|
+
'posts_per_page' => 5,
|
62
|
+
|
63
|
+
'post_status' => 'publish'
|
64
|
+
|
65
|
+
);
|
66
|
+
|
57
|
-
|
67
|
+
$myquery = new WP_Query( $args );
|
58
68
|
|
59
69
|
?>
|
60
70
|
|
71
|
+
<?php if ( $myquery->have_posts()): ?>
|
61
72
|
|
73
|
+
<?php while($myquery->have_posts()): $myquery->the_post(); ?>
|
62
74
|
|
63
75
|
<div class="d-flex">
|
64
76
|
|
@@ -90,100 +102,12 @@
|
|
90
102
|
|
91
103
|
<hr class="my-2" />
|
92
104
|
|
93
|
-
<?php
|
105
|
+
<?php endwhile; ?>
|
94
106
|
|
95
|
-
|
107
|
+
<?php endif; ?>
|
96
108
|
|
97
|
-
|
109
|
+
<?php wp_reset_postdata(); ?>
|
98
110
|
|
99
|
-
?>
|
100
|
-
|
101
|
-
<div class="d-flex justify-content-between mb-2 mt-3 bg-black pl-3 py-2">
|
102
|
-
|
103
|
-
<p class="font-weight-bold mb-0 text-white">同じエリアの記事</p>
|
104
|
-
|
105
|
-
<p class="h8 mb-0 pr-4 pt-1">
|
106
|
-
|
107
|
-
<a href='/area' class="text-white">もっと見る</a>
|
108
|
-
|
109
|
-
</p>
|
110
|
-
|
111
|
-
</div>
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
<?php
|
116
|
-
|
117
|
-
$custom_post_tag = 'area';
|
118
|
-
|
119
|
-
$terms = wp_get_object_terms($post->ID, $custom_post_tag);
|
120
|
-
|
121
|
-
$slug = $term->slug;
|
122
|
-
|
123
|
-
if($slug=='area_hokkaido'){
|
124
|
-
|
125
|
-
query_posts( array(
|
126
|
-
|
127
|
-
'post_type' => 'area',
|
128
|
-
|
129
|
-
'taxonomy' => 'areanews',
|
130
|
-
|
131
|
-
'slug' => 'area_hokkaido' ,
|
132
|
-
|
133
|
-
'posts_per_page' => 5,
|
134
|
-
|
135
|
-
'numberposts' => '-1'
|
136
|
-
|
137
|
-
)
|
138
|
-
|
139
|
-
);
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
if (have_posts()) :while (have_posts()) :
|
144
|
-
|
145
|
-
the_post();
|
146
|
-
|
147
|
-
?>
|
148
|
-
|
149
|
-
<div class="d-flex">
|
150
|
-
|
151
|
-
<div class="w-30">
|
152
|
-
|
153
|
-
<a href="<?php the_permalink(); ?>" class="d-block overflow-hidden img-cropped">
|
154
|
-
|
155
|
-
|
111
|
+
<?php } // ループの終了 ?>
|
156
|
-
|
157
|
-
<?php echo wp_get_attachment_image( get_field('メイン画像'), 'thumbnail', false, array( 'class' => 'img-fluid' ) ); ?>
|
158
|
-
|
159
|
-
<?php else : ?>
|
160
|
-
|
161
|
-
<img src="/example.png" class="img-fluid" alt="No_image_available">
|
162
|
-
|
163
|
-
<?php endif; ?>
|
164
|
-
|
165
|
-
</a>
|
166
|
-
|
167
|
-
</div>
|
168
|
-
|
169
|
-
<div class="w-70">
|
170
|
-
|
171
|
-
<p class="h9 ml-2"><a href="<?php the_permalink(); ?>" class="text-body"><?php the_title(); ?></a></p>
|
172
|
-
|
173
|
-
</div>
|
174
|
-
|
175
|
-
</div>
|
176
|
-
|
177
|
-
<hr class="my-2" />
|
178
|
-
|
179
|
-
<?php
|
180
|
-
|
181
|
-
endwhile;
|
182
|
-
|
183
|
-
endif;
|
184
|
-
|
185
|
-
wp_reset_query();
|
186
|
-
|
187
|
-
?>
|
188
112
|
|
189
113
|
```
|