2

I need to change the language of some 500 posts in a site that uses WPML. Currently all of them are set to English, but are in fact in Spanish.

What is the fastest way to do so? It is possible to get the IDs of all of the posts.

3

I've done it with this bit of code:

global $wpdb;

$posts = get_posts(array('post_type'=>'...', 'posts_per_page'=>-1));
foreach($posts as $post) {
    $wpdb->update('wp_icl_translations', array('language_code'=>'es'), array('element_id'=> $post->ID));
}
  • Very useful! In case there's a way nowadays to detect and fix this via the WPML UI, I'd be interested (if there is it's not obvious to me…) – William Turrell Dec 7 '18 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.