Finding the correct query in bricks

<?php
/** find the correct query in bricks when it doesn't match the existing rules in the addon
 ** example is for a query loop in product archive
 **/

/** skip the default archive query **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
  if ( $query->is_main_query() && $query->get( 'wc_query', false ) ) {
    $is_main_query = false;
  }
  return $is_main_query;
}, 10, 2 );

/** uses global loop counter to skip occurances of the same query within the 
 ** query loop until we get to the correct one **/
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {  
  if ( 'b872e8' == $element_id ) { // element id https://d.pr/i/77hzdI
    global $loop_counter;
    $loop_counter = ( empty( $loop_counter ) ) ? 1 : $loop_counter+1;    
    if ( 2 < $loop_counter ) { // 2 could be changed for other types if needed
        $query_vars['facetwp'] = true;
    } else {
      $query_vars['facetwp'] = false;
    }
  }
  return $query_vars;
}, 11, 3 );