@@ -143,7 +143,8 @@ public static function get_loop_query( $attributes ) {
143
143
$ post__not_in = array ( get_the_ID () );
144
144
}
145
145
146
- $ offset = isset ( $ attributes ['offset ' ] ) ? intval ( $ attributes ['offset ' ] ) : 0 ;
146
+ $ offset = isset ( $ attributes ['offset ' ] ) ? intval ( $ attributes ['offset ' ] ) : 0 ;
147
+ $ posts_per_page = isset ( $ attributes ['numberPosts ' ] ) ? intval ( $ attributes ['numberPosts ' ] ) : 0 ;
147
148
148
149
$ date_query = array ();
149
150
if ( ! empty ( $ attributes ['targetPeriod ' ] ) ) {
@@ -179,14 +180,17 @@ public static function get_loop_query( $attributes ) {
179
180
}
180
181
181
182
global $ wp_query ;
183
+
182
184
// とりあえず1を入れつつ2ページ目の情報があったら上書き
183
185
$ paged = 1 ;
184
186
if ( ! empty ( $ attributes ['pagedlock ' ] ) ) {
185
187
$ paged = 1 ;
186
188
} elseif ( is_singular () && isset ( $ wp_query ->query_vars ['page ' ] ) ) {
187
- $ paged = $ wp_query ->query_vars ['page ' ];
189
+ $ paged = $ wp_query ->query_vars ['page ' ] ? $ wp_query ->query_vars ['page ' ] : 1 ;
190
+ $ offset = $ offset + $ posts_per_page * ( $ paged - 1 );
188
191
} elseif ( isset ( $ wp_query ->query_vars ['paged ' ] ) ) {
189
- $ paged = $ wp_query ->query_vars ['paged ' ];
192
+ $ paged = $ wp_query ->query_vars ['paged ' ] ? $ wp_query ->query_vars ['paged ' ] : 1 ;
193
+ $ offset = $ offset + $ posts_per_page * ( $ paged - 1 );
190
194
}
191
195
192
196
$ args = array (
@@ -195,16 +199,19 @@ public static function get_loop_query( $attributes ) {
195
199
'tax_query ' => ! empty ( $ is_checked_terms ) ? self ::format_terms ( $ tax_query_relation , $ is_checked_terms , $ is_checked_post_type ) : array (),
196
200
'paged ' => $ paged ,
197
201
// 0で全件取得
198
- 'posts_per_page ' => intval ( $ attributes [ ' numberPosts ' ] ) ,
202
+ 'posts_per_page ' => $ posts_per_page ,
199
203
'order ' => $ attributes ['order ' ],
200
204
'orderby ' => $ attributes ['orderby ' ],
201
- 'offset ' => $ offset ,
202
205
'post__not_in ' => array_map ( 'intval ' , $ post__not_in ),
203
206
'date_query ' => $ date_query ,
204
207
'update_post_meta_cache ' => false ,
205
208
'no_found_rows ' => true ,
206
209
);
207
210
211
+ if ( ! is_null ( $ offset ) ) {
212
+ $ args ['offset ' ] = $ offset ;
213
+ }
214
+
208
215
if ( ! empty ( $ date_query ) ) {
209
216
$ args ['date_query ' ] = $ date_query ;
210
217
}
0 commit comments