回答編集履歴
2
コード追記(動作未検証)
answer
CHANGED
@@ -6,4 +6,99 @@
|
|
6
6
|
参考URL
|
7
7
|
|
8
8
|
[http://notnil-creative.com/blog/archives/1996](http://notnil-creative.com/blog/archives/1996)
|
9
|
-
[http://notnil-creative.com/blog/archives/1688](http://notnil-creative.com/blog/archives/1688)
|
9
|
+
[http://notnil-creative.com/blog/archives/1688](http://notnil-creative.com/blog/archives/1688)
|
10
|
+
|
11
|
+
---
|
12
|
+
**追記**
|
13
|
+
1.はpre_get_postsフックを使用する形に変更。
|
14
|
+
2.は元の形にpagedパラメータだけ追加。
|
15
|
+
|
16
|
+
**動作未検証なので、参考までに**
|
17
|
+
**動かない場合は、各変数に想定した値が入っているかを、var_dump()等で確かめてください**
|
18
|
+
|
19
|
+
1.
|
20
|
+
```PHP
|
21
|
+
// 動作未検証
|
22
|
+
function teratail74248_ttaishi_pre_get_posts($query) {
|
23
|
+
if ( !is_admin() && $query->is_main_query() ) {
|
24
|
+
if ($query->is_search) {
|
25
|
+
$s = $query->get('s');
|
26
|
+
$item = $query->get('item');
|
27
|
+
$item_type = $query->get('item_type');
|
28
|
+
$shop = $query->get('shop');
|
29
|
+
|
30
|
+
if($item){
|
31
|
+
$taxquerysp[] = array(
|
32
|
+
'taxonomy'=> $item_type,
|
33
|
+
'terms'=> $item,
|
34
|
+
'include_children'=>false,
|
35
|
+
'field'=>'slug',
|
36
|
+
'operator'=>'AND'
|
37
|
+
);
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
$term_objs = get_terms($item_type);
|
41
|
+
$terms = array();
|
42
|
+
foreach($term_objs as $term){
|
43
|
+
$terms[] = $term->slug;
|
44
|
+
}
|
45
|
+
$taxquerysp[] = array(
|
46
|
+
'taxonomy' => $item_type,
|
47
|
+
'field' => 'slug',
|
48
|
+
'terms' => $terms,
|
49
|
+
'operator' => 'IN',
|
50
|
+
'include_children' => false,
|
51
|
+
);
|
52
|
+
}
|
53
|
+
if($shop){
|
54
|
+
$taxquerysp[] = array(
|
55
|
+
'taxonomy'=>'shop_info',
|
56
|
+
'terms'=> $shop,
|
57
|
+
'include_children'=>false,
|
58
|
+
'field'=>'slug',
|
59
|
+
'operator'=>'AND'
|
60
|
+
);
|
61
|
+
}
|
62
|
+
if($information){
|
63
|
+
$taxquerysp[] = array(
|
64
|
+
'taxonomy'=>'item_info',
|
65
|
+
'terms'=> $information,
|
66
|
+
'include_children'=>false,
|
67
|
+
'field'=>'slug',
|
68
|
+
'operator'=>'AND'
|
69
|
+
);
|
70
|
+
}
|
71
|
+
$taxquerysp['relation'] = 'AND';
|
72
|
+
|
73
|
+
$query->set('post_type', 'petinfo');
|
74
|
+
$query->set('posts_per_page', 24);
|
75
|
+
$query->set('tax_query', $taxquerysp);
|
76
|
+
$query->set('s', $s);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
add_action( 'pre_get_posts','teratail74248_ttaishi_pre_get_posts' );
|
81
|
+
```
|
82
|
+
|
83
|
+
2.
|
84
|
+
```PHP
|
85
|
+
// 動作未検証
|
86
|
+
<?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; ?>
|
87
|
+
<ul id="item_news_list">
|
88
|
+
<?php
|
89
|
+
$args = array(
|
90
|
+
'paged' => $paged ,
|
91
|
+
'post_type' => 'post',
|
92
|
+
'posts_per_page' => -1
|
93
|
+
);
|
94
|
+
$domestic_post = get_posts($args);
|
95
|
+
if($domestic_post) : foreach($domestic_post as $post) : setup_postdata( $post );
|
96
|
+
get_template_part('loop-news_list'); ?>
|
97
|
+
<?php the_title(); ?>
|
98
|
+
<?php endforeach; ?>
|
99
|
+
<?php else : ?>
|
100
|
+
<li>表示する記事がありません。</li>
|
101
|
+
<?php endif;
|
102
|
+
wp_reset_postdata(); ?>
|
103
|
+
</ul>
|
104
|
+
```
|
1
体裁修正
answer
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
query_postsおよびget_postsをテンプレートファイル内で記述しているために、ページ送りが機能していないものと思われます。
|
2
|
-
かわりにpre_get_postsフックを利用してください。
|
2
|
+
かわりに**pre_get_postsフック**を利用してください。
|
3
|
+
|
3
4
|
---
|
4
5
|
|
5
6
|
参考URL
|