- الحالة
- محلولة
نظرة عامة على المشكلة
بالنسبة لبعض أنواع حقول 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، إلخ، بناءً على ذلك.
هذا هو نوع العنصر الذي ينتمي إليه المعرف. يمكن أن يكون post، page، attachment، {custom post type key}، nav_menu، nav_menu_item، category، post_tag، {custom taxonomy key}
لمزيد من المعلومات، يرجى الاطلاع على وثائق الخطّاف الخاصة بنا هنا.