Skip to content

Commit e59b336

Browse files
committed
Fixed infinite loop in subsections
1 parent f5114f3 commit e59b336

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

includes/frontend/class-display.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ public static function render_product_sections( $product_id, $args ) {
225225
* @return string Formatted output.
226226
*/
227227
public static function get_knowledge_base_loop( $term_id, $level, $nested = true, $args = array() ) {
228+
// Recursion guard: skip if this term_id has already been rendered.
229+
if ( isset( $args['visited_term_ids'] ) && in_array( $term_id, $args['visited_term_ids'], true ) ) {
230+
return '';
231+
}
232+
// Add this term_id to visited_term_ids for recursion tracking.
233+
if ( ! isset( $args['visited_term_ids'] ) ) {
234+
$args['visited_term_ids'] = array();
235+
}
236+
$args['visited_term_ids'][] = $term_id;
237+
228238
// Special handling for root level (term_id = 0) in single product mode.
229239
if ( 0 === $term_id && 0 === $level ) {
230240
$output = '';

0 commit comments

Comments
 (0)