[Solved] - Nested query loop for woocommerce products

Hi,

I am facing a somewhat peculiar problem.

I had implemented this nested query system in another site and it worked perfectly.

But on my development site, I am encountering a problem.

I have a query on a custom taxonomy that works, and within this query, I want to display a certain number of Woocommerce products related to this custom taxonomy.

By adding the information in the taxonomy query, as I had done previously, I do not get the expected results at all.

Have you ever had this situation?
Is it possible with Bricks Builder to achieve this?

Thanks in advance. :slight_smile:

Edit:

My faultā€¦ :scream:

The client wanted to remove a product category for visitors not connected to the siteā€¦
An error in my code present in the functions.php to alter the ā€œpre_get_postsā€ did not add the exception in the request but replaced itā€¦ Now itā€™s working!

If you are interested, here is the code:

function custom_search_filter($query) {
  // Get the current user
  $user = wp_get_current_user();
  // Check if the user is an administrator
  $is_administrator = in_array('administrator', $user->roles);
  // Check if the user is a store manager
  $is_shop_manager = in_array('shop_manager', $user->roles);
  // Check if user is logged in
  $is_user_logged_in = is_user_logged_in();
  // Check if user is member of role 'client_specific_role'
  $is_specific_role_member = $is_user_logged_in && in_array('client_specific_role', $user->roles);

  // If the user is an administrator or shop manager or member of the client_specific_role, do nothing
  if ($is_administrator || $is_specific_role_member || $is_shop_manager) {
      return;
  }
  $excluded_category = 'category_name_to_be_excluded';
      $tax_query = array(
          array(
              'taxonomy' => 'product_cat',
              'field'    => 'slug',
              'terms'    => $excluded_category_slug,
              'operator' => 'NOT IN',
              'include_children' => true,
          ),
      ); 
  // Merges with any other tax_queries
  $existing_tax_query = $query->get('tax_query') ?: [];
  $query->set('tax_query', array_merge($existing_tax_query, $tax_query));
}
add_action('pre_get_posts', 'custom_search_filter');