Перейти к содержанию Перейти к боковой панели
Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 12:00 7:00 – 12:00 7:00 – 12:00 7:00 – 12:00 7:00 – 12:00 -
- 13:00 – 15:00 13:00 – 15:00 13:00 – 15:00 13:00 – 15:00 13:00 – 15:00 -

Часовой пояс сторонника: Europe/Madrid (GMT+02:00)

Эта тема содержит 0 ответ, имеет 1 голос.

Последнее обновление: danielM-79 1 год, 1 месяц назад.

При содействии: Carlos Rojas.

Автор Посты
14 июня, 2024 в 11:16 дп #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?

Тема '[Закрытые] Translating post ID stored as meta field' закрыта для новых ответов.