質問編集履歴

1

コードの全文を追記しました。

2022/03/15 15:40

投稿

haru.k.ah
haru.k.ah

スコア0

test CHANGED
File without changes
test CHANGED
@@ -38,6 +38,91 @@
38
38
  その結果、ワーニングは消え、ページネーションは作れたのですが、何も表示されないページが複数ページできました。
39
39
  ページネーションを作る時のcount()のワーニングの対応方法や空欄のページの消し方などわかる方がいらっしゃいましたらアドバイスをお願いします。
40
40
 
41
+ ---------------コードの全文は以下になります。------------
42
+
43
+ public function tags_page() {
44
+ global $question_tags, $ap_max_num_pages, $ap_per_page, $tags_rows_found;
45
+ $paged = max( 1, get_query_var( 'paged' ) );
46
+ $per_page = (int) ap_opt( 'tags_per_page' );
47
+ $per_page = 0 === $per_page ? 1 : $per_page;
48
+ $offset = $per_page * ( $paged - 1 );
49
+
50
+ $tag_args = array(
51
+ 'taxonomy' => 'question_tag',
52
+ 'ap_tags_query' => true,
53
+ 'parent' => 0,
54
+ 'number' => $per_page,
55
+ 'offset' => $offset,
56
+ 'hide_empty' => false,
57
+ 'order' => 'DESC',
58
+ );
59
+
60
+ $ap_sort = ap_isset_post_value( 'tags_order', 'count' );
61
+
62
+ if ( 'new' === $ap_sort ) {
63
+ $tag_args['orderby'] = 'id';
64
+ $tag_args['order'] = 'DESC';
65
+ } elseif ( 'name' === $ap_sort ) {
66
+ $tag_args['orderby'] = 'name';
67
+ $tag_args['order'] = 'ASC';
68
+ } else {
69
+ $tag_args['orderby'] = 'count';
70
+ }
71
+
72
+ if ( ap_isset_post_value( 'ap_s' ) ) {
73
+ $tag_args['search'] = ap_sanitize_unslash( 'ap_s', 'r' );
74
+ }
75
+
76
+ /**
77
+ * Filter applied before getting tags.
78
+ *
79
+ * @var array
80
+ */
81
+ $tag_args = apply_filters( 'ap_tags_shortcode_args', $tag_args );
82
+
83
+ $query = new \WP_Term_Query( $tag_args );
84
+
85
+ // Count terms.
86
+ $tag_args['fields'] = 'count';
87
+ $found_query = new \WP_Term_Query( $tag_args );
88
+ $tags_rows_found = $found_query->get_terms();
89
+ //$ap_max_num_pages = ceil( count( $tags_rows_found ) / $per_page ); // ← この行がエラーとなった
90
+
91
+
92
+
93
+
94
+ //ここから変更
95
+
96
+ $total_terms = wp_count_terms(
97
+ '$question_tags',
98
+ array(
99
+ 'hide_empty' => false,
100
+ 'parent' => 0,
101
+ )
102
+ );
103
+
104
+ $ap_max_num_pages = ceil( $total_terms / $per_page );
105
+
106
+
107
+ $order = ap_opt( 'tags_page_order' ) === 'ASC' ? 'ASC' : 'DESC';
108
+
109
+ $cat_args = array(
110
+ 'parent' => 0,
111
+ 'number' => $per_page,
112
+ 'offset' => $offset,
113
+ 'hide_empty' => false,
114
+ 'orderby' => ap_opt( 'tags_page_orderby' ),
115
+ 'order' => $order,
116
+ );
117
+
118
+
119
+
120
+ //ここまで追記
121
+
122
+
123
+ $question_tags = $query->get_terms();
124
+ include ap_get_theme_location( 'addons/tag/tags.php' );
125
+ }
41
126
 
42
127
 
43
128