Tell us what you are trying to do?
I'm working on a wordpress script to import posts from an excel file. I dynamically create the english post using 'wpml_set_element_language_details', so fra everything works fine except for the category translation, there's always french category that is inserted.
Here's my code :
$data_post = array(
'post_date' => $article['created_at'],
'post_type' => 'post',
'post_title' => $article['name'] ,
'post_excerpt' => $article['introduction'] ,
'post_content' => $article['text'] ,
'post_status' => $active,
'post_slug' => $article['slug'],
'post_category' => array(117) , // this is the translated category id
);
Hi, I still need assistance on this.
I've changed the default language in WPML > Language > Site Languages, and it works. The a category is the english one.
Does it have a way to change dynamically change the default language instead of changing it in the setting.
Thanks for your assistance
Your site's default language is French, and you are trying to add English content, and that is indeed where the source of the problem lies.
When you programmatically insert a post, it is characterised as French by WPML (the default language).
I think you just need to change the sequencing a little for this to work.
Insert the post without the category.
Use the wpml_set_element_language_details hook to update the post to specify that it is in fact English.
And then update the post to apply the English category.
You have most of the code in place that you require already, so I assume you can try that.