Copying/Cloning Elementor content to a new post programatically so it can be translated

811 Views Asked by At

I am developing a plugin for Polylang that takes the content of selected posts and saves it to an XLIFF-file that can be sent to a translation agency. When the translated XLIFF is returned, I create new translated posts and link them with Polylang functions. Polylang works in such a way, that each translation is a cloned post that is linked in their database.

Everything works nicely with Classic Editor, Gutenberg and any page builder that uses shortcodes to build the post->post_content.

However, Elementor does not seem to work with shortcodes, but instead uses it's own database tables to save the content.

I can get the rendered Elementor content from a post, but that is just html and while I can save it to a post content, it can longer be edited with Elementor.

I could basically try to get the content by using the IDs I get with $elementor->documents->get_doc_for_frontend( $post_id )->get_elements_data();, save that as translatable objects in the XLIFF, but I havent figured out how to clone the Elementor post so that there are new IDs and then replace the content in those. Or something...

Is anyone aware of existing immplementations where an Elementor-page is cloned and some of the resulting pages text content replaced?

1

There are 1 best solutions below

3
On

All the relavant data is stored in the wp_postmeta table with around 10 rows per post.

In the field meta_value of post_id = '$post_id' AND meta_key = '_elementor_data' you find a JSON-like content. The parts to translate are i.e. editor, text, title.

I hope this helps - please keep me informed about further updates.