Skip to content

Instantly share code, notes, and snippets.

@Zenger
Created November 11, 2013 11:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Zenger/7411575 to your computer and use it in GitHub Desktop.
Save Zenger/7411575 to your computer and use it in GitHub Desktop.
wp_insert_post and WPML
<?php
global $wpdb;
// Insert the original post
$original = wp_insert_post($array, true);
// Insert the translated post
$translated = wp_insert_post($array, true);
// Make some updates to both translations
update_post_meta();
wp_set_object_terms();
// ... and so on
// Associate translated language and original language
$trid = wpml_get_content_trid('post_<your_custom_post_type>', $original );
$wpdb->update( $wpdb->prefix.'icl_translations', array( 'trid' => $trid, 'language_code' => '<your_language_code>', 'source_language_code' => wpml_get_default_language() ), array( 'element_id' => $translated ) );
// That's it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment