patrickA-12
|
Problem with WPML ACF Multilingual when the ACF select field is dynamically populated with a multidimensional array
|
Waqas Bin Hasan
Supporter
Languages:
English (English )
Timezone:
Asia/Karachi (GMT+05:00)
|
Hi,
Reference to our chat, I've reported this ticket as well.
Meanwhile, as you noted in the other thread (https://wpml.org/forums/topic/acf-select-optgroup-causes-fatal-error/), please use the workaround mentioned by our devs:
Edit classes/Strings/Traversable/Field.php and replace
protected function transform( Transformer $transformer, $value, $config ) {
if ( is_array( $value ) ) {
foreach ( $value as $key => $label ) {
$value[ $key ] = $transformer->transform( $label, $config );
}
} else {
$value = $transformer->transform( $value, $config );
}
return $value;
}
with
protected function transform( Transformer $transformer, $value, $config ) {
if ( is_array( $value ) ) {
foreach ( $value as $key => $label ) {
if ( is_string( $label ) ) {
$value[ $key ] = $transformer->transform( $label, $config );
}
}
} else {
$value = $transformer->transform( $value, $config );
}
return $value;
}
And if you want to translate the strings, you need to update the code in the functions.php file to
add_filter('acf/load_field/key=field_6452d0242b965',function($field) {
$field['choices'] = array(
'group1'=>array('val1'=> __( 'Value 1', 'my_plugin' ), 'val2'=> __( 'Value 2', 'my_plugin' )),
'group2'=>array('val3'=> __( 'Value 3', 'my_plugin' ), 'val4'=> __( 'Value 4', 'my_plugin' )),
);
return $field;
});
Regards.
|