Using an ACF field in this example to customize the WordPress Query Loop Block pre-rendered posts.
add_filter( 'pre_render_block', function( $pre_render, $parsed_block ) {
// Require ACF Plugin
if( ! function_exists( 'get_field' ) ) {
return $pre_render;
}
$term = get_queried_object();
// Using Custom Field
$custom_field = get_field( 'custom_field', $term );
if( $custom_field ) {
add_filter( 'query_loop_block_query_vars',
function( $query, $block ) use( $custom_field ) {
$query['post__in'] = $custom_field;
return $query;
}, 10, 2 );
}
// Using Current Post Category
add_filter( 'query_loop_block_query_vars',
function( $query, $block ) use( $term ) {
$query['post__not_in'] = [ get_the_ID( $term ) ];
foreach( get_the_category( $term ) as $category_term ) {
$query['category_name'] = $category_term->slug;
}
return $query;
}, 10, 2 );
// Return
return $pre_render;
}, 10, 2 );