- availability:
-
WPML Version: 4.9.4
- description:
-
This filter is useful when you import translations without their associated source post (which is already on the site). It allows 3rd-party code to retrieve a translation record ID (trid) to reconnect original content with its imported translations.
Use cases:
– Originals exist on the site (not imported), while translations are imported from an external source (spreadsheet or external tool).
– Originals were previously imported and their import meta was cleaned up; new language translations are added later.
– Any workflow where translations must be connected to originals via a shared business key (SKU, slug, external ID, etc.).
- type:
- filter
- category:
- Inserting Content
- parameters:
-
add_filter( 'wpml_import_get_trid_from_imported_translations', integer $trid, object $firstTranslation )
$trid (int|null)
The trid resolved by the importer, or null if none was found.
$firstTranslation (object)
The first translation post object, with properties: element_id, translation_group, language_code, source_language_code.
- hook example usage:
-
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 );