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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: America/Los_Angeles (GMT-07:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by Bobby 1 year, 4 months ago.

Assisted by: Bobby.

Author Posts
January 9, 2024 at 2:20 pm #15165080

lorenzoR-22

I would need to know how to query the content of a translated post (or page). The knowledge of WPML tables and webhooks is insufficient...

Here is an example:
SELECT * FROM `wp_posts`
INNER JOIN wp_icl_translations t ON wp_posts.ID = t.element_id
WHERE post_author = 2

This one can show that the content is a normal html for untranslated posts. For the translated one I'm not sure how to extract them

January 9, 2024 at 6:02 pm #15166124

lorenzoR-22

This is to confirm the previous findings (earlier from the wp_post table) using WPML tables as seen in the attached query image: the BODY of the translated post (which I do read translated in the front end) is empty, field_translate and field_finished are even zero. The title, however, is indicated correctly, it was translated and I can find the translation too.

phpAdmin_WPML.png
January 10, 2024 at 8:07 pm #15171417

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

I would like to verify that I fully understand your request:

You are looking for a SQL query that extracts the translations of a post along with their title and post content, is that right?

What is the primary goal you are attempting to achieve with this SQL query, i see that my colleague has referenced the import/export tool to move translations from one site to another.

perhaps there is a more "simple" way of doing this.

January 10, 2024 at 10:54 pm #15171827

lorenzoR-22

Yes, you understood the question perfectly! The import/export plugin was a misunderstanding not worth elaborating. What makes it complicated is that WPML seems to translate one to many languages, not any pair of languages (for a given website). Since I cannot use the same "base" language for both websites, I am forced to transfer a translation. Example: site.it is in Italian and site.fr is in French -- you write a post in Italian in site.it and want it to appear in French in site.fr. If site.it sends the post in IT, site.fr cannot translate it because its base language is French, so site.it needs to translate it to French first and then send the translation to site.fr. The translation exists, I read it is stored too (to avoid replicated translations), but I can only retrieve the translated title, the translated post body is just empty (the field is filled with a html hidden comment that says "translatedWithWPMLTM").

January 11, 2024 at 6:22 pm #15176347

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

let's use the same example you mentioned site.it and site.fr are these 2 separate sites or would it be possible for you to set up the language URL format "different domain per language"

which would allow you to have your base language site (Italian) and then the translations would like under the domain site.fr both would be under the same WordPress environment.

Review the following documentation, please:
https://wpml.org/documentation/getting-started-guide/language-setup/language-url-options/#a-different-domain-per-language

https://wpml.org/documentation/getting-started-guide/language-setup/language-url-options/how-to-use-wpml-with-different-domains-per-language/

let me know if that would work.

January 11, 2024 at 11:47 pm #15176890

lorenzoR-22

The two websites share only some information (posts of international relevance), otherwise they contain local posts in the local language. Also, posts of international relevance can be created from any of the two sites (published also on the other site in a different language). Given the different languages to translate, each site has its own WPML.

The query in the screenshot attached on Jan. 9 is simplistic but yet the post body has a "WPML" signature and for unknown reasons nothing else. A WPML developer would know immediately why and where that translation is stored.

January 15, 2024 at 6:50 pm #15186545

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for the additional information, please note that when it comes to custom work our support is limited.

I have brought your question to the attention of our dev team in case they can provide some feedback as this is not a typical use case of WPML.

Once I have some feedback I will update you here.

January 16, 2024 at 6:49 pm #15191824

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

I will share our dev team's feedback to your request:

"It is better to use a plugin like the import/export plugin than a SQL query.

Some posts rely on icl_strings and icl_string_translations table and pulling them just like that won't be sufficient (depends on the page builder)."

https://wpml.org/download/wpml-export-and-import/?section=changelog

January 16, 2024 at 7:16 pm #15191882

lorenzoR-22

That plugin (already discarded before but it keeps re-emerging) cannot be used to export a single post translation as soon as it is published and import it in another site automatically. It is for bulk transfers with several manual steps.

I don't use any fancy page builder, they are confusing. Please ask a database master, the answer will be quick even if the query is complicated, it would have saved a lot of time to all, thanks!

January 17, 2024 at 7:14 pm #15196649

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Please note that I am directly discussing this with our dev team and my colleague is an expert when it comes to database work.

I will ask again, but I am going to urge you to review the following documentation and give the plugin we mentioned a try. In the documentation I share with you, it's used in conjunction with WP All Import.

https://wpml.org/documentation/related-projects/wpml-export-and-import/

Please let me know your results after going through the documentation shared. You should be able to do this with just 1 export/import, no need for bulk work.

January 18, 2024 at 10:01 pm #15202449

lorenzoR-22

Please don't close this ticket, I have to go on a trip for an emergency in the family. I will test this plugin again, I did not realize before that I can export/import only one post and maybe even with command line, so I can run it 100 times per day in a fully automated fashion? I will be happy to test this feature that you say exists and I did not see before, but next week, so no answer in the next days does not mean it is solved.

January 19, 2024 at 5:23 pm #15205978

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

There is an automatic function that closes our tickets after a certain time passes with inactivity, you should be ok for now.

If by chance it does close automatically please open a new ticket and reference this one or ask to be connected with me and we will be able to continue.

When you do have time, yes, please review the documentation and test it then let me know your results.

I also had some feedback from our developer team, while providing a full solution with SQL will indeed require some custom work (which we do not cover in the forum) we hope that the following provides some hints and help.

--------------------------------------------------------

The query that you are using is fetching the information only from the posts table.

Many page builders store their info in the postmeta table - so it depends on actually what the postmeta has for that same post.

Along with the wp_posts, he should probably export the data for the postmeta as well - it all depends on the page builder...

For which you would probably need another query like:

SELECT * FROM `wp_postmeta`
INNER JOIN wp_icl_translations AS t ON wp_postmeta.post_id = t.element_id INNER JOIN wp_posts AS p on wp_postmeta.post_id = p.ID
WHERE post_author = 2

Also if you would like to export only the translated content, perhaps add a condition to check for source_language_code being not NULL:

SELECT *
FROM `wp_posts`
INNER JOIN `wp_icl_translations` AS t ON wp_posts.ID = t.element_id
WHERE post_author = 2 AND t.source_language_code IS NOT NULL

This will list only the translated posts and not the originals.

The topic ‘[Closed] How to extract translated content from Database using queries’ is closed to new replies.