inpsyde / wpml2mlp

Convert posts from an existing WPML multilingual site via WXR Export/Import for MultilingualPress
https://wordpress.org/plugins/wpml-to-multilingualpress/
GNU General Public License v2.0
10 stars 6 forks source link

Export: improve get_language_info() #16

Closed luminuu closed 8 years ago

luminuu commented 8 years ago

In inc/Wpml2mlp_Helper.php the function get_language_info() retrieves the language for the given post. The SQL retrieves the first entry it gets by the post ID from the database. However, in the wp_icl_translations table there can be more than one entry for the post ID, with a different element_type, on grown WPML installations:

test1

As you can see in the above screenshot, the row with the element_type comment has a different language_code as the second entry, which is the one we need. As in the get_language_info() function the SQL only gets the first row, the exported XLIFF files are completely mixed up with wrong entries on each language file.

To do: The SQL does not only need to check on the correct post ID, but also on the correct post type. In the function get_all_posts() of the inc/Wpml2mlp_Helper.php file, the post types are selected and used to retrieve the posts needed for the export. The same get_post_types() function can be used to check on all possible post types within the wp_icl_translations table for retrieving the correct language of each post.