- Статус
- Решено
Обзор проблемы
Для некоторых типов полей ACF невозможно корректно дублировать контент.
Обходное решение
Если Вы используете какие-либо поля, перечисленные в разделе «Полное описание» этой записи, Вам следует добавить этот фрагмент кода в файл functions.php Вашей темы оформления, чтобы дублирование работало правильно.
function wpml_fix_acf_duplication( $value_to_filter, $target_language, $meta_data ) {
// Field names should be placed into following array.
$fields = array(
'test_taxonomy' => 'some_taxonomy_name',
'test_image' => 'attachment',
'test_file' => 'attachment',
'test_gallery' => 'attachment',
'test_post_object' => 'post',
'test_page_link' => 'page'
);
if ( array_key_exists( $meta_data['key'], $fields ) ) {
$value = maybe_unserialize( $value_to_filter );
if ( is_array( $value ) ) {
// If custom field value contain array of IDs to translate, usually used for gallery and taxonomy field types.
$translated_ids = array();
foreach ( $value as $v ) {
$translated_ids[] = apply_filters( 'wpml_object_id', $v, $fields[ $meta_data['key'] ], true, $target_language );
}
return maybe_serialize( $translated_ids );
} else {
// If custom field value contain single ID to translate, usually used for image and file field types.
$translated_id = apply_filters( 'wpml_object_id', $value, $fields[ $meta_data['key'] ], true, $target_language );
return $translated_id;
}
}
return $value_to_filter;
}
add_filter( 'wpml_duplicate_generic_string', 'wpml_fix_acf_duplication', 999, 3 );
ПРИМЕЧАНИЕ: Вам следует заменить пары массива key => value на соответствующие значения.
Замените ключи, такие как «test_taxonomy», «test_image», «test_file» и т. д., на названия полей Вашего сайта, как показано в следующем примере на изображении.

Соответствующим образом замените значения, такие как «some_taxonomy_name», «attachment», post, page и т. д.
Это тип элемента, которому принадлежит ID. Может быть post, page, attachment, {custom post type key}, nav_menu, nav_menu_item, category, post_tag, {custom taxonomy key}
Для получения дополнительной информации ознакомьтесь с нашей документацией по хукам здесь.