- สถานะ
- แก้ไขแล้ว
ภาพรวมของปัญหา
สำหรับประเภทฟิลด์ 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} ได้
สำหรับข้อมูลเพิ่มเติม โปรดดูเอกสารประกอบเกี่ยวกับฮุกของเราได้ที่นี่