I’m trying to figure out how to create a translation for a post using the internal WPML API (inc/wpml-api.php
)
I simply want to create a translation for post ID xx, set some content and publish it.
I’ve tried to play around with wpml_add_translatable_content
but couldn’t get it right. Unfortunately there is not much documentation available for this. The closest lead I found is this thread, but I couldn’t reduce the code to what I need. It’s also possible to do this by directly writing to the database, following WPML’s table structure, but I want to use the API.
Any suggestions are welcome.
I came up with a function that does the job for now :
Answer is still good, but if you’re having this error
Call to undefined function wpml_get_content_trid()
Replace this :
With this :
WPML Documentation : https://wpml.org/wpml-hook/wpml_element_trid/
I didn’t find any documentation for
wpml_get_content_trid()
function. I don’t really know if this function was deleted in WPML updates or if there is something missing in my code.