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.

Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

Tagged: 

This topic contains 2 replies, has 0 voices.

Last updated by Itamar 2 weeks, 2 days ago.

Assisted by: Itamar.

Author Posts
August 12, 2025 at 1:39 pm #17313708

itzikE

Background of the issue:
I am trying to run a post-processing function immediately after a post (or translation) is saved and WPML has assigned its TRID and language details. I’m using the wpml_after_save_post hook with the following code:

```php
add_action( 'wpml_after_save_post', function( $post_id, $trid ) {
$post_type = get_post_type( $post_id );
$trid_from_filter = apply_filters( 'wpml_element_trid', null, $post_id, 'post_' . $post_type );
error_log( "Hook param TRID: " . var_export( $trid, true ) );
error_log( "Filter TRID: " . var_export( $trid_from_filter, true ) );
}, 10, 2 );
```

Link to a page where the issue can be seen:

Symptoms:
When saving a post and creating translations, the $trid in the hook is null, and wpml_element_trid returns an incorrect value. I expected the $trid parameter in wpml_after_save_post to always contain the correct translation group ID, and calling apply_filters('wpml_element_trid', ...) for the same post should return that same TRID. Instead, $trid is null in wpml_after_save_post, and apply_filters('wpml_element_trid', ...) returns a TRID that does not belong to the current translation group or belongs to a different post.

Questions:
Why is the $trid parameter null in the wpml_after_save_post hook?
Why does apply_filters('wpml_element_trid', ...) return an incorrect TRID?

August 13, 2025 at 8:47 pm #17319239

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

May I ask, please, from where the wpml_after_save_post hook has been taken?
I'm checking our hooks reference page at the following link and can't find this hook.
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

In any case, I'm also consulting our second-tier supporters about this.
I'll update you here once I have their reply.

Regards,
Itamar.

August 19, 2025 at 6:47 pm #17332569

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

This is the reply from our second-tier supporter.

The hook wpml_after_save_post should already be providing the trid for a particular post. Perhaps the issue is that the other two parameters are not in use there? Like language code and source language code. Without debugging this, I cannot say exactly. Maybe something is affecting the user code, and there is more to the issue.

In light of the above, any further details from your side would be appreciated.

Also, please share your site's Debug information if you need further help with this issue. You can read about it here: http://wpml.org/faq/provide-debug-information-faster-support/.

Regards,
Itamar.

The topic ‘[Closed] There seems to be a timing bug with the wpml_after_save_post hook. The $trid parameter is null, and …’ is closed to new replies.