@@ -192,11 +192,11 @@ public function presave_alter_values( Fieldmanager_Field $field, $values, $curre
192
192
$ tax_values = $ value ;
193
193
}
194
194
}
195
- $ this ->save_taxonomy ( $ tax_values , $ field-> data_id );
195
+ $ this ->pre_save_taxonomy ( $ tax_values , $ field );
196
196
}
197
197
if ( $ this ->only_save_to_taxonomy ) {
198
198
if ( empty ( $ values ) && ! ( $ this ->append_taxonomy ) ) {
199
- $ this ->save_taxonomy ( array (), $ field-> data_id );
199
+ $ this ->pre_save_taxonomy ( array (), $ field );
200
200
}
201
201
return array ();
202
202
}
@@ -215,7 +215,7 @@ public function presave( Fieldmanager_Field $field, $value, $current_value ) {
215
215
* @param mixed[] $tax_values
216
216
* @return void
217
217
*/
218
- public function save_taxonomy ( $ tax_values , $ data_id ) {
218
+ public function pre_save_taxonomy ( $ tax_values , $ field ) {
219
219
220
220
$ tax_values = array_map ( 'intval ' , $ tax_values );
221
221
$ tax_values = array_unique ( $ tax_values );
@@ -227,14 +227,16 @@ public function save_taxonomy( $tax_values, $data_id ) {
227
227
$ taxonomies_to_save = array ();
228
228
foreach ( $ tax_values as $ term_id ) {
229
229
$ term = $ this ->get_term ( $ term_id );
230
- if ( empty ( $ taxonomies_to_save [ $ term ->taxonomy ] ) ) $ taxonomies_to_save [ $ term ->taxonomy ] = array ();
231
- $ taxonomies_to_save [ $ term ->taxonomy ][] = $ term_id ;
232
- }
233
- foreach ( $ taxonomies_to_save as $ taxonomy => $ terms ) {
234
- wp_set_object_terms ( $ data_id , $ terms , $ taxonomy , $ this ->append_taxonomy );
230
+ if ( empty ( $ field ->current_context ->taxonomies_to_save [ $ term ->taxonomy ] ) ) {
231
+ $ field ->current_context ->taxonomies_to_save [ $ term ->taxonomy ] = array ();
232
+ }
233
+ $ field ->current_context ->taxonomies_to_save [ $ term ->taxonomy ][] = $ term_id ;
235
234
}
236
235
} else {
237
- wp_set_object_terms ( $ data_id , $ tax_values , $ taxonomies [0 ], $ this ->append_taxonomy );
236
+ if ( ! isset ( $ field ->current_context ->taxonomies_to_save [ $ taxonomies [0 ] ] ) ) {
237
+ $ field ->current_context ->taxonomies_to_save [ $ taxonomies [0 ] ] = array ();
238
+ }
239
+ $ field ->current_context ->taxonomies_to_save [ $ taxonomies [0 ] ] = array_merge ( $ field ->current_context ->taxonomies_to_save [ $ taxonomies [0 ] ], $ tax_values );
238
240
}
239
241
}
240
242
0 commit comments