File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 4343 };
4444
4545 $ terms = $ walker ( $ all_terms , wp_list_pluck ( $ objects , 'term_id ' ) );
46- $ choices = array ();
46+ $ filtered_choices = array ();
4747
4848 foreach ( $ terms as $ object ) {
49- $ choices [] = array (
49+ $ choice = array (
5050 'value ' => $ object ->term_id ,
5151 'text ' => $ object ->name ,
5252 'object ' => $ object ,
5353 );
54+
55+ // For Multi Choice fields with persistent choices, preserve existing choice structure.
56+ if ( method_exists ( $ field , 'has_persistent_choices ' ) && $ field ->has_persistent_choices () ) {
57+ // Find matching choice in original choices to preserve key and other properties
58+ foreach ( $ choices as $ original_choice ) {
59+ if ( isset ( $ original_choice ['object ' ] ) && $ original_choice ['object ' ]->term_id == $ object ->term_id ) {
60+ $ choice = array_merge ( $ original_choice , $ choice );
61+ break ;
62+ }
63+ }
64+ // If no existing choice found, generate key for new choices
65+ if ( ! isset ( $ choice ['key ' ] ) ) {
66+ $ choice ['key ' ] = md5 ( $ object ->term_id );
67+ }
68+ }
69+
70+ $ filtered_choices [] = $ choice ;
5471 }
5572
56- return $ choices ;
73+ return $ filtered_choices ;
5774}, 10 , 3 );
You can’t perform that action at this time.
0 commit comments