I use chatgpt for translation =P
Hi everyone!
I’ve seen that many people in the community struggle with WPML translations and don’t know how to solve it.
Today, I managed to find a solution and wanted to share the step-by-step in case it helps anyone.
I was able to fix it by creating a custom endpoint in functions.php.
Then, I created the posts in each language individually using the WordPress modules, and finally linked them together using the custom endpoint through an HTTP Request.
Hope this is helpful to some of you!
How I Solved It (WPML + Make.com Multilingual Posting)
In the end, this is how I solved it:
1. Creating the multilingual posts
I use the WordPress – Make an API Call module in Make.com to create content in different languages.
For each language, I send a POST request to the following URL:
CopyEdit
posts?lang=XX
Where XX is the language code (e.g., ca, en, es, etc.).
The JSON body looks like this:
json
CopyEdit
{
"title": "Translated title",
"content": "<p>Translated HTML content</p>",
"status": "publish",
"excerpt": "Translated excerpt",
"slug": "my-slug"
}
See Screenshots 167 and 168
2. Linking translations with a custom endpoint
Since WPML doesn’t provide an official REST API to link translations, I created a custom endpoint in functions.php using the hook wpml_set_element_language_details.
Here’s the code I added:
php
CopyEdit
// ============= Link Translation endpoint (WPML) =============
add_action( 'rest_api_init', function () {
register_rest_route( 'link_translation', '/post', [
'methods' => 'POST',
'callback' => 'lt_link_translation',
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
'args' => [
'original' => [ 'type' => 'integer', 'required' => true ],
'translation' => [ 'type' => 'integer', 'required' => true ],
'lang' => [ 'type' => 'string', 'required' => true ],
],
] );
} );
function lt_link_translation( WP_REST_Request $req ) {
$orig_id = $req->get_param( 'original' );
$trans_id = $req->get_param( 'translation' );
$lang_code = $req->get_param( 'lang' );
$el_type = apply_filters( 'wpml_element_type', 'post' );
$info = apply_filters(
'wpml_element_language_details',
null,
[ 'element_id' => $orig_id, 'element_type' => $el_type ]
);
if ( empty( $info->trid ) ) {
return new WP_Error( 'no_trid', 'TRID not found for original post', [ 'status' => 400 ] );
}
do_action( 'wpml_set_element_language_details', [
'element_id' => $trans_id,
'element_type' => $el_type,
'trid' => $info->trid,
'language_code' => $lang_code,
'source_language_code' => $info->language_code,
] );
return [ 'status' => 'linked', 'trid' => $info->trid ];
}
// =============================================================
3. Linking posts via Make.com
Once the posts are created, I send a POST request to:
bash
CopyEdit
/wp-json/link_translation/post
With this JSON payload:
json
CopyEdit
{
"original": post_id_es_without_quotes,
"translation": post_id_en_without_quotes,
"lang": "short_lang_code_of_translation_post (e.g., en, ca, es...)"
}
See Screenshots 165 and 166



