<?php
/** experimental compatibility for generateblocks query loop https://wordpress.org/plugins/generateblocks/
** tested for use in pages not archives
** add facetwp-template class to the loop's grid - https://d.pr/i/JbABCf - this is a setting on the grid not the query
**/
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'facetwp-template' ) !== false ) {
$query_args['facetwp'] = true;
if ( FWP()->request->is_preload && isset( FWP()->request->url_vars['paged'] ) ) {
$page = (int) FWP()->request->url_vars['paged'];
} elseif ( isset( $_POST['data']['paged'] ) ) {
$page = (int) $_POST['data']['paged'];
} else {
$page = 1;
}
if ( 1 < $page ) {
$offset = ( $query_args['posts_per_page'] * ( $page - 1 ) );
$query_args['paged'] = $page;
$query_args['offset'] = $offset;
}
}
return $query_args;
}, 10, 2 );