function kb_get_product_group_items($product_id) { $terms = wp_get_post_terms( $product_id, 'kb_product_group' ); if (empty($terms) || is_wp_error($terms)) { return []; } $group = $terms[0]; $posts = get_posts([ 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'post__not_in' => [$product_id], 'tax_query' => [ [ 'taxonomy' => 'kb_product_group', 'field' => 'term_id', 'terms' => $group->term_id, ] ], 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ]); $items = []; foreach ($posts as $post) { $product = wc_get_product($post->ID); if (!$product) { continue; } $items[] = [ 'id' => $post->ID, 'card' => kb_get_product_loop_data($product), ]; } return $items; }