Navigation überspringen
Sun Mon Tue Wed Thu Fri Sat
12:00 – 20:00 12:00 – 20:00 12:00 – 20:00 12:00 – 20:00 12:00 – 20:00 - -
- - - - - - -

Unterstützt die Zeitzone: Asia/Karachi (GMT+05:00)

Schlagwörter: 

Dieses Thema enthält 0 Antworten, hat 1 Stimme.

Zuletzt aktualisiert von antonT-13 Vor 1 Monat, 1 Woche.

Assistiert von: Noman.

Verfasser Beiträge
Januar 12, 2025 unter 3:07 pm #16585910

antonT-13

Background of the issue:
Hello WPML Support Team,

I am developing a plugin extension for WPML to streamline translation creation from a single interface. However, I’ve encountered an issue: when updating post statuses in a loop, everything works fine for the original post, but when I attempt to update a translation (not the original), the translation gets deleted after the second iteration of the loop.

Here’s the code I’m using:

if ($duplicate_action === 'skip' && $duplicate_action !== "del" && is_object($existing_translation) && !empty($target_lang['id']) && !empty($target_lang['check'])) {

if (empty($target_lang['check'])) return;

if ($existing_translation->language_code !== $target_lang['leng']) {

error_log("Skipped: language mismatch. Expected {$target_lang['leng']}, got {$existing_translation->language_code}");

return;

}

$updated_post_data = [

'ID' => $existing_translation->element_id,

'post_status' => $publish_option,

];

$updated_post_id = wp_update_post($updated_post_data);

if ($updated_post_id) {

$s_language_code = $existing_translation->source_language_code ?? null;

$trid = $this->sitepress->get_element_trid(, 'post_post');

if (!empty($trid)) {

do_action('wpml_set_element_language_details', [

'element_id' => $updated_post_id,

'element_type' => 'post_post',

'trid' => $trid,

'language_code' => $target_lang['leng'],

'source_language_code' => $s_language_code,

'check_duplicates' => false,

]);

} else {

error_log("TRID is missing for element ID: $updated_post_id");

}

}

return null;

}

On the first iteration, the translation updates correctly. However, on the next loop iteration, the translation is deleted, and I cannot figure out why this happens. I’ve added error logs for debugging, but they don’t provide a clear explanation.

Could you help clarify why the translation might be deleted during updates using wp_update_post and do_action('wpml_set_element_language_details')? Perhaps I am missing an essential step in working with the WPML API.

Thank you in advance for your assistance!

Symptoms:
On the first iteration, the translation updates correctly. However, on the next loop iteration, the translation is deleted.

Questions:
Could you help clarify why the translation might be deleted during updates using wp_update_post and do_action('wpml_set_element_language_details')?
Perhaps I am missing an essential step in working with the WPML API.

Das Thema '[Geschlossen] Issue with Post Status Updates in WPML Extension Development' ist für neue Antworten geschlossen.