WPML
add_filter( 'wpml_import_get_trid_from_imported_translations', integer $trid, object $firstTranslation )
ประเภท
filter
เวอร์ชันของ WPML
4.9.4

คำอธิบาย

ฟิลเตอร์นี้มีประโยชน์เมื่อคุณนำเข้าการแปลโดยไม่มีโพสต์ต้นทางที่เกี่ยวข้องกัน (ซึ่งมีอยู่แล้วบนไซต์) ฟิลเตอร์นี้ช่วยให้โค้ดของบุคคลที่สามสามารถดึง ID บันทึกการแปล (trid) เพื่อเชื่อมต่อเนื้อหาต้นฉบับเข้ากับการแปลที่นำเข้าอีกครั้ง

กรณีการใช้งาน:

- ต้นฉบับมีอยู่แล้วบนไซต์ (ไม่ได้นำเข้า) ในขณะที่การแปลถูกนำเข้าจากแหล่งข้อมูลภายนอก (สเปรดชีตหรือเครื่องมือภายนอก)

- ต้นฉบับถูกนำเข้ามาก่อนหน้านี้และข้อมูล meta ของการนำเข้าถูกล้างไปแล้ว โดยมีการเพิ่มการแปลภาษาใหม่ในภายหลัง

- เวิร์กโฟลว์ใด ๆ ที่ต้องเชื่อมต่อการแปลเข้ากับต้นฉบับผ่านคีย์ธุรกิจที่ใช้ร่วมกัน (SKU, slug, ID ภายนอก ฯลฯ)

อาร์กิวเมนต์

$trid (int|null)

ค่า trid ที่ตัวนำเข้ากำหนด หรือเป็น null หากไม่พบ

$firstTranslation (object)

ออบเจ็กต์โพสต์การแปลแรก ซึ่งมีคุณสมบัติ: element_id, translation_group, language_code, source_language_code

ตัวอย่างการใช้งาน

add_filter( 'wpml_import_get_trid_from_imported_translations', 
function( $trid, $firstTranslation ) {
if ( $trid ) {
return $trid;
}

$sku = get_post_meta( $firstTranslation->element_id, '_sku', true );
if ( ! $sku ) {
return $trid;
}

// Find the original post with the same SKU and return its trid.
$original_id = wc_get_product_id_by_sku( $sku );
if ( ! $original_id ) {
return $trid;
}

$details = apply_filters( 'wpml_element_language_details', null, [
'element_id' => $original_id,
'element_type' => 'post_product',
] );

return $details ? $details->trid : $trid;
}, 10, 2 );

wpml_set_element_language_details, wpml_make_post_duplicates, wpml_admin_make_post_duplicates, wpml_copy_post_to_language, wpml_delete_package, wpml_register_string, wpml_register_single_string, wpml_show_package_language_ui, wpml_delete_package_action

ฮุก การแทรกเนื้อหา ทั้งหมด 10 รายการ →