GenerateBlocks and MB Relationships

It’s been tough to find answers on how to use MB Relationships (from metabox.io) with GenerateBlocks… but I have found how to filter a GB Query Loop based on a MB Relationship, so I thought I would share the code snippet:

add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {  
    if ( ! is_admin() &&
        ! empty( $attributes['className'] ) &&
        strpos( $attributes['className'], 'arbitrary-css-class' ) !== false // Define "arbitrary-css-class" CSS class to add to the Grid block inside your GB Query Loop
    ) {
        return array_merge( $query_args, array(
            'relationship' => [
                'id' => 'event_to_provider', // Pass your relationship ID
                'to' => get_the_ID(), // You can pass object ID or full object
            ],
        ) );
    }
 
    return $query_args;
}, 10, 2 );

You’re welcome!