回答編集履歴
2
コード追記(動作未検証)
test
CHANGED
@@ -15,3 +15,193 @@
|
|
15
15
|
[http://notnil-creative.com/blog/archives/1996](http://notnil-creative.com/blog/archives/1996)
|
16
16
|
|
17
17
|
[http://notnil-creative.com/blog/archives/1688](http://notnil-creative.com/blog/archives/1688)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
**追記**
|
24
|
+
|
25
|
+
1.はpre_get_postsフックを使用する形に変更。
|
26
|
+
|
27
|
+
2.は元の形にpagedパラメータだけ追加。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
**動作未検証なので、参考までに**
|
32
|
+
|
33
|
+
**動かない場合は、各変数に想定した値が入っているかを、var_dump()等で確かめてください**
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
1.
|
38
|
+
|
39
|
+
```PHP
|
40
|
+
|
41
|
+
// 動作未検証
|
42
|
+
|
43
|
+
function teratail74248_ttaishi_pre_get_posts($query) {
|
44
|
+
|
45
|
+
if ( !is_admin() && $query->is_main_query() ) {
|
46
|
+
|
47
|
+
if ($query->is_search) {
|
48
|
+
|
49
|
+
$s = $query->get('s');
|
50
|
+
|
51
|
+
$item = $query->get('item');
|
52
|
+
|
53
|
+
$item_type = $query->get('item_type');
|
54
|
+
|
55
|
+
$shop = $query->get('shop');
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
if($item){
|
60
|
+
|
61
|
+
$taxquerysp[] = array(
|
62
|
+
|
63
|
+
'taxonomy'=> $item_type,
|
64
|
+
|
65
|
+
'terms'=> $item,
|
66
|
+
|
67
|
+
'include_children'=>false,
|
68
|
+
|
69
|
+
'field'=>'slug',
|
70
|
+
|
71
|
+
'operator'=>'AND'
|
72
|
+
|
73
|
+
);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
else {
|
78
|
+
|
79
|
+
$term_objs = get_terms($item_type);
|
80
|
+
|
81
|
+
$terms = array();
|
82
|
+
|
83
|
+
foreach($term_objs as $term){
|
84
|
+
|
85
|
+
$terms[] = $term->slug;
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
$taxquerysp[] = array(
|
90
|
+
|
91
|
+
'taxonomy' => $item_type,
|
92
|
+
|
93
|
+
'field' => 'slug',
|
94
|
+
|
95
|
+
'terms' => $terms,
|
96
|
+
|
97
|
+
'operator' => 'IN',
|
98
|
+
|
99
|
+
'include_children' => false,
|
100
|
+
|
101
|
+
);
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
if($shop){
|
106
|
+
|
107
|
+
$taxquerysp[] = array(
|
108
|
+
|
109
|
+
'taxonomy'=>'shop_info',
|
110
|
+
|
111
|
+
'terms'=> $shop,
|
112
|
+
|
113
|
+
'include_children'=>false,
|
114
|
+
|
115
|
+
'field'=>'slug',
|
116
|
+
|
117
|
+
'operator'=>'AND'
|
118
|
+
|
119
|
+
);
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
if($information){
|
124
|
+
|
125
|
+
$taxquerysp[] = array(
|
126
|
+
|
127
|
+
'taxonomy'=>'item_info',
|
128
|
+
|
129
|
+
'terms'=> $information,
|
130
|
+
|
131
|
+
'include_children'=>false,
|
132
|
+
|
133
|
+
'field'=>'slug',
|
134
|
+
|
135
|
+
'operator'=>'AND'
|
136
|
+
|
137
|
+
);
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
$taxquerysp['relation'] = 'AND';
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
$query->set('post_type', 'petinfo');
|
146
|
+
|
147
|
+
$query->set('posts_per_page', 24);
|
148
|
+
|
149
|
+
$query->set('tax_query', $taxquerysp);
|
150
|
+
|
151
|
+
$query->set('s', $s);
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
add_action( 'pre_get_posts','teratail74248_ttaishi_pre_get_posts' );
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
2.
|
166
|
+
|
167
|
+
```PHP
|
168
|
+
|
169
|
+
// 動作未検証
|
170
|
+
|
171
|
+
<?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; ?>
|
172
|
+
|
173
|
+
<ul id="item_news_list">
|
174
|
+
|
175
|
+
<?php
|
176
|
+
|
177
|
+
$args = array(
|
178
|
+
|
179
|
+
'paged' => $paged ,
|
180
|
+
|
181
|
+
'post_type' => 'post',
|
182
|
+
|
183
|
+
'posts_per_page' => -1
|
184
|
+
|
185
|
+
);
|
186
|
+
|
187
|
+
$domestic_post = get_posts($args);
|
188
|
+
|
189
|
+
if($domestic_post) : foreach($domestic_post as $post) : setup_postdata( $post );
|
190
|
+
|
191
|
+
get_template_part('loop-news_list'); ?>
|
192
|
+
|
193
|
+
<?php the_title(); ?>
|
194
|
+
|
195
|
+
<?php endforeach; ?>
|
196
|
+
|
197
|
+
<?php else : ?>
|
198
|
+
|
199
|
+
<li>表示する記事がありません。</li>
|
200
|
+
|
201
|
+
<?php endif;
|
202
|
+
|
203
|
+
wp_reset_postdata(); ?>
|
204
|
+
|
205
|
+
</ul>
|
206
|
+
|
207
|
+
```
|
1
体裁修正
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
query_postsおよびget_postsをテンプレートファイル内で記述しているために、ページ送りが機能していないものと思われます。
|
2
2
|
|
3
|
-
かわりにpre_get_postsフックを利用してください。
|
3
|
+
かわりに**pre_get_postsフック**を利用してください。
|
4
|
+
|
5
|
+
|
4
6
|
|
5
7
|
---
|
6
8
|
|