teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

サブループを新たに設定してみましたが、だめだったことの報告を追加しました。

2021/12/09 08:39

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -59,9 +59,116 @@
59
59
  ```
60
60
 
61
61
  ### 試したこと
62
- いろいろ試しているうちに、ワードプレスの「設定 > 表示設定」にある『1ページに表示する最大投稿数』と連携?連動?して数値が変動していることがわかり、上記ソースコードにあるように、$the_queryの後に採番してみましたがだめでした。
62
+ 0. いろいろ試しているうちに、ワードプレスの「設定 > 表示設定」にある『1ページに表示する最大投稿数』と連携?連動?して数値が変動していることがわかり、上記ソースコードにあるように、$the_queryの後に採番してみましたがだめでした。
63
+ 0. 表示の設定に連動することがわかり、投稿に関する抽出用のサブループを設定していないのかなと思って、下記の通り、サブループを設定してみました。なんの関連性もない数値が返ってきて、どうしたらよいか迷走しています。
64
+ ```php
63
65
 
66
+ /*------------------------------------------------------------------------------------
67
+ /* カスタマイズ:月間集計用ショートコード
68
+ /*----------------------------------------------------------------------------------*/
69
+ function sumMM(){
64
70
 
71
+ // 初期化
72
+ $countMM = 0;
73
+
74
+ // 設定ページIDの設定
75
+ $sid = 189;
76
+
77
+ // 月間集計の設定読込
78
+ if ( have_rows( 'set_kzn_month' , $sid ) ) :
79
+ while ( have_rows( 'set_kzn_month' , $sid ) ) : the_row();
80
+ $set_m_start = get_sub_field( 'set_m_start' , $sid );
81
+ $set_m_end = get_sub_field( 'set_m_end' , $sid );
82
+ endwhile;
83
+ endif;
84
+
85
+ $KZM_Query = new WP_Query(
86
+ array(
87
+ 'post_type' => 'post',
88
+ 'post_status' => 'publish'
89
+ )
90
+ );
91
+
92
+ if($KZM_Query -> have_posts()):
93
+ while($KZM_Query -> have_posts()):
94
+ $KZM_Query -> the_post();
95
+
96
+ // ページIDの取得
97
+ $tid = get_the_ID();
98
+
99
+ // 基本情報の取得
100
+ if ( have_rows( 'kzn_info' , $tid ) ) :
101
+ while ( have_rows( 'kzn_info' , $tid ) ) : the_row();
102
+ $kzn_reg_date = get_sub_field( 'kzn_reg_date' , $tid );
103
+ if( ( $kzn_reg_date > $set_m_start ) && ( $kzn_reg_date <= $set_m_end ) ){ $countMM++; }
104
+ endwhile;
105
+ endif;
106
+
107
+ endwhile;
108
+
109
+ endif;
110
+
111
+ wp_reset_postdata();
112
+
113
+ return $countMM;
114
+ }
115
+ add_shortcode('sumMM','sumMM');
116
+
117
+ /*------------------------------------------------------------------------------------
118
+ /* カスタマイズ:年間集計用ショートコード
119
+ /*----------------------------------------------------------------------------------*/
120
+ function sumYY(){
121
+
122
+ // カウンタ初期化
123
+ $countYY = '0';
124
+
125
+ // 設定ページIDの設定
126
+ $sid = 189;
127
+
128
+ // 月間集計設定の読込
129
+ if ( have_rows( 'set_kzn_year' , $sid ) ) :
130
+ while ( have_rows( 'set_kzn_year' , $sid ) ) : the_row();
131
+ $set_y_start = get_sub_field( 'set_y_start' , $sid );
132
+ $set_y_end = get_sub_field( 'set_y_end' , $sid );
133
+ endwhile;
134
+ endif;
135
+
136
+
137
+
138
+ $KZY_Query = new WP_Query(
139
+ array(
140
+ 'post_type' => 'post',
141
+ 'post_status' => 'publish'
142
+ )
143
+ );
144
+
145
+ if($KZY_Query -> have_posts()):
146
+ while($KZY_Query -> have_posts()):
147
+ $KZY_Query -> the_post();
148
+
149
+ // ページIDの取得
150
+ $tid = get_the_ID();
151
+
152
+ // 基本情報の取得
153
+ if ( have_rows( 'kzn_info' , $tid ) ) :
154
+ while ( have_rows( 'kzn_info' , $tid ) ) : the_row();
155
+ $kzn_reg_date = get_sub_field( 'kzn_reg_date' , $tid );
156
+ if( ( $kzn_reg_date > $set_y_start ) && ( $kzn_reg_date <= $set_y_end ) ){ $countYY++; }
157
+ endwhile;
158
+ endif;
159
+
160
+ endwhile;
161
+
162
+ endif;
163
+
164
+ wp_reset_postdata();
165
+
166
+ return $countYY;
167
+ }
168
+ add_shortcode('sumYY','sumYY');
169
+ ```
170
+
171
+
65
172
  ### 補足情報
66
173
  ・ワードプレスのバージョン:5.8.2
67
174
  ・ワードプレスの使用テーマ:hummingbird