Categories
programming

Update posts language after installing WPML plugin for wordpress

WPML is a plugin that enables a worpress site to write post in different languages. You only have to install the plugin and all works.. wel not all. If you already have lot of articles written in your language, the main page of your site will show anything due that there is no pages with that language. However, you can execute a small SQL sentence to solve this problem, here we go:

INSERT INTO wp_icl_translations(element_type, element_id, trid, language_code)
SELECT 'post', `ID`, 1, "es" FROM `wp_posts` WHERE `post_status`="publish"

and for the categories also:

INSERT INTO wp_icl_translations(element_type, element_id, trid, language_code)
SELECT 'category', `term_taxonomy_id`, 0, "es" FROM `wp_term_taxonomy` WHERE `taxonomy`="category";

and last, make some cleaning tasks:

UPDATE `wp_icl_translations` SET `source_language_code` = ""

* Replace the “es” string with the appropriate language.