Skip Navigation

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 reply, has 0 voices.

Last updated by Kor 6 months ago.

Author Posts
January 12, 2025 at 3:16 pm #16585929

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. Error logs do not provide a clear explanation.

Questions:
Why might the translation be deleted during updates using wp_update_post and do_action('wpml_set_element_language_details')?
Am I missing an essential step in working with the WPML API?

January 14, 2025 at 8:59 am #16591886

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for contacting WPML support.

To help speed up the support process, I've enabled a private message for submitting the debug information for this support ticket. Please follow these initial debugging steps:
https://wpml.org/faq/provide-debug-information-faster-support/
In short:
- Go to "WPML > Support > Debug Information" (link)
- Copy the Debug Information from there.
- Find the private field I activated and paste that information.

Please share with us the WordPress debug.log
Access your server via FTP and open wp-config.php (in your WordPress root directory).
Insert those lines just before

/* That's all, stop editing! Happy blogging. */
	define( 'WP_DEBUG', true );
	define( 'WP_DEBUG_LOG', true );
	define( 'WP_DEBUG_DISPLAY', false );

Reproduce the issue, then access the debug log here: /wp-content/debug.log and copy and paste the info in your next answer.

The topic ‘[Closed] Issue with Post Status Updates in WPML Extension Development’ is closed to new replies.