Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 voice and has 0 replies.

>
Author Posts
October 12, 2023 at 2:50 pm #14567029

Andrea

I'm still dealing with custom posts synchronization, as I have lots of IT, EN & FR posts not linked to each other (IT should be the source language). I've found the "wpml_set_element_language_details" action hook and maybe this is what I need, but maybe I'm missing something.
I've tested the following code (just for one post in french), but not working - maybe beacuse is hooked to the wrong hook (wp_footer)? The wpml_element_language_details is working, meaning that the info are retrieved, but it looks like that the wpml_set_element_language_details action is not operating...

function test_custom_post_link()
{
$original_post_language_info = apply_filters('wpml_element_language_details', null, array('element_id' => <the-id-of-the-source-post>, 'element_type' => 'post_<the-slug-of-the-custom-post>');

$set_language_args = array(
'element_id' => <the-id-of-the-target-fr-post-to-be-linked>,
'element_type' => 'post_<the-slug-of-the-custom-post>',
'trid' => $original_post_language_info->trid,
'language_code' => 'fr',
'source_language_code' => $original_post_language_info->language_code
);

do_action('wpml_set_element_language_details', $set_language_args);
}

add_action('wp_footer', 'test_custom_post_link');

October 12, 2023 at 3:02 pm #14567181

Andrea

...looks like that my code works fine - in my first attempts I've used just the custom post slug instead of post_slug