Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions gp-populate-anything/gppa-filter-terms-by-depth.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,32 @@
};

$terms = $walker( $all_terms, wp_list_pluck( $objects, 'term_id' ) );
$choices = array();
$filtered_choices = array();

foreach ( $terms as $object ) {
$choices[] = array(
$choice = array(
'value' => $object->term_id,
'text' => $object->name,
'object' => $object,
);

// For Multi Choice fields with persistent choices, preserve existing choice structure.
if ( method_exists( $field, 'has_persistent_choices' ) && $field->has_persistent_choices() ) {
// Find matching choice in original choices to preserve key and other properties
foreach ( $choices as $original_choice ) {
if ( isset( $original_choice['object'] ) && $original_choice['object']->term_id == $object->term_id ) {
$choice = array_merge( $original_choice, $choice );
break;
}
}
// If no existing choice found, generate key for new choices
if ( ! isset( $choice['key'] ) ) {
$choice['key'] = md5( $object->term_id );
}
}

$filtered_choices[] = $choice;
}

return $choices;
return $filtered_choices;
}, 10, 3 );