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:
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?
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.