7 Responses

  1. akinori Kul
    akinori Kul September 1, 2014 at 2:25 AM |

    Thank you for this article and sharing your solution, it helped me a lot.

    wpml_get_content_trid was raising an error for me because I was using “post_properties”. Having a look to wp3_icl_translations table in wordpress dbb, I realize that you should use “post_post” for post content type.

  2. Thiago
    Thiago April 15, 2015 at 9:47 PM |

    I got an error using $trigid = wpml_get_content_trid(‘post_page’, $adden);
    Error: Call to undefined function wpml_get_content_trid()

    So I went straight to:

    $trigid = $sitepress->get_element_trid($adden, ‘post_page’);

    That works !
    Also important to remember to call global $sitepress;

  3. Leonardo
    Leonardo March 4, 2016 at 4:51 PM |

    Hi, my solution is not very elegant but it seems to work.
    NOTE: “poi” is my custom post type.

    global $sitepress;
    $defaultLanguage = $sitepress->get_default_language();

    $pid = wp_insert_post( array(
    ‘post_title’ => ‘the post title!’,
    ‘post_status’ => ‘publish’,
    ‘post_type’ => ‘poi’,

    if ($lang != $defaultLanguage){
    $trid = $sitepress->get_element_trid($pid, “post_poi”);
    $sitepress->set_element_language_details($pid, “post_poi”, $trid, $lang);
    else {
    // no action to do: post is already in right language

  4. How to Programmatically Add Multi Language Post in WordPress and WPML | queue

    […] Source: How to Programmatically Add Multi Language Post in WordPress and WPML […]

  5. anton
    anton January 16, 2017 at 2:43 AM |

    Here is another way is duplicate post and update post data

    //in $postarray is original english post data

    $post_id = wp_insert_post($postarray);
    foreach ($langs_to_duplicate as $lang) {
    $tr_post_id = $sitepress->make_duplicate( $post_id, $lang );
    echo ‘Duplicated post ID: ‘.$tr_post_id.’ for Lang is: ‘.$lang.”;
    $postarray = get_post_data_by_lang($lang);
    $postarray[‘ID’] = $tr_post_id;
    $postarray[‘post_author’] = 1;
    if (wp_update_post($postarray, true)){
    echo ‘Updated post ID: ‘.$tr_post_id.’ Lang is: ‘.$lang.”;

  6. anton
    anton January 17, 2017 at 1:57 AM |

    Useful if you use duplicate:

    //delete duplicate relation to prevent lose changes in secondary langs if english was changed
    $wpdb->query(“delete from wp_postmeta where meta_key = ‘_icl_lang_duplicate_of’;”);

Comments are closed.