Please make sure to update to WPML 4.3.6 and check our list of Known Issues before reporting

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.

This topic contains 6 replies, has 2 voices.

Last updated by sarah.n 6 years, 10 months ago.

Assigned support staff: sarah.n.

Author Posts
March 5, 2013 at 12:21 am #108849

Mona

Hi,

I have built a multi-language website via three categories : US / FR / AR, since three years.

I'd like to use WPML in this website, so I need to affect all the articles from the FR category to "FR" language, all articles from the AR category to "arabic" language, etc...

Is there a way to do that? What is the process for an existing website to migrate to WPML?

Thank you for your help.

March 5, 2013 at 7:19 am #108888

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Hello Mona,

You will probably need to run a custom function that loops through all posts and based on their category sets the language details for each.

Below you will find some example code. Please note that it has not been tested so I would not use it on a live site. Better would be that you create a test site and test it there first.

global $sitepress;
$args = array('numberposts' => 1);
$posts_array = get_posts( $args );
foreach($posts_array as $post){
	$categories = get_the_category($post->ID);
	$post_trid = $sitepress->get_element_trid($post->ID, 'post_post');		
	switch($categories[0]->name){
			case 'FR':
				$sitepress->set_element_language_details($post->ID, 'post_post', $post_trid, 'fr', $sitepress->get_default_language(), true);
			break;					
			case 'AR':
				$sitepress->set_element_language_details($post->ID, 'post_post', $post_trid, 'AR', $sitepress->get_default_language(), true);
			break;
			case 'US':
				$sitepress->set_element_language_details($post->ID, 'post_post', $post_trid, 'en', NULL, true);
			break;
		}
	}

Note: The default language (I am assuming it is US in the code above) will have NULL as the 5th parameter in the $sitepress->set_element_language_details() function.

This should hopefully point you to the right direction.

March 5, 2013 at 5:56 pm #109155

Mona

Hi Sarah,

OK, I tried your code by adding it on my functions.php file. What next ? I thought that by logged in my dashboard it will run the function but nothing, the articles are always all considered as "English" by WPML.

I realize that there is this tutorial:http://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-using-content-duplication/

Is it adapted for my case? Can I duplicate all posts that are in "FR" category to "English" translation, and then remove all "US" posts from this category?

March 5, 2013 at 6:44 pm #109182

Mona

Nop, doesn't run because when I remove the English version of one post, it's removing the French translation too...

In fact, here is what I need:
- Assign "french" language to all articles that are under "french" parent category (and its child categories).
- Remove all the English versions of these posts, because they are only in French.

At the end, all french articles must be considered as "french" by WPML without any other languages, and all English articles (those who are not in "french" category) must be considered as English by WPML, without any translations.
Is there a way to do that?

March 6, 2013 at 8:54 am #109337

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Mona,

There is a way to do that but it requires custom programming. In this case please consider contacting one of our certified partners: http://wpml.org/documentation/support/wpml-contractors/

March 21, 2013 at 4:21 pm #113864

Mona

Thank Sarah. I have finally made it manually via Translation Management. It took me time but It's fine now!
Thank you for your help.

March 22, 2013 at 6:06 am #113953

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

OK great! Thank you for the update on this.