Skip to content

Instantly share code, notes, and snippets.

@freezvd
Forked from Zenger/wp_insert_post.php
Created May 3, 2017 11:35
Show Gist options
  • Save freezvd/5c3920891ef7195d726dafc2efe936e0 to your computer and use it in GitHub Desktop.
Save freezvd/5c3920891ef7195d726dafc2efe936e0 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