Skip Navigation

This topic contains 0 replies, has 1 voice.

Last updated by danielM-79 3 months, 1 week ago.

Assisted by: Carlos Rojas.

Author Posts
June 14, 2024 at 11:16 am #15739822

danielM-79

Background of the issue:
We have a dual language (English [default lang], Turkish) education related website. It has 2 custom post types: courses and institutes (university). Each course is linked to a university via a meta field (course_institute) that stores the ID of the institute, either the English or the Turkish post ID, depending on the translation of the course. We use this code to find and store the Turkish ID of the institute, whenever a Turkish translation of a course is created or updated. However, often this code is not executed.

add_action('wpml_pro_translation_completed', function($post_id, $fields, $job) {
$lang = apply_filters( 'wpml_post_language_details', '', $post_id );
$lang = isset($lang['language_code']) ? $lang['language_code'] : '';

$default_language = apply_filters( 'wpml_default_language', NULL );
$original_course_id = apply_filters( 'wpml_object_id', $post_id, 'post', true, $default_language );

$original_institute_id = get_post_meta($original_course_id, 'course_institute', true);
$translated_institute_id = apply_filters( 'wpml_object_id', $original_institute_id, 'university', false, $lang );

update_post_meta($post_id, 'course_institute', $translated_institute_id);
}, 10, 3);

Symptoms:
The code to find and store the Turkish ID of the institute is often not executed.

Questions:
Which is the recommended hook or solution to guarantee that the action is executed when a translation is updated or finished?
Is there any documentation that you are following?

The topic ‘[Closed] Translating post ID stored as meta field’ is closed to new replies.