Title: Programmatically Create a Translated page?
Last modified: October 5, 2016

---

# Programmatically Create a Translated page?

 *  Resolved [Firstcode](https://wordpress.org/support/users/diegotheswede/)
 * (@diegotheswede)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/programmatically-create-a-translated-page/)
 * Whats the hook/function to insert a translation of an existing page programmatically
   from another plugin etc into mealingua? Or do I just need to add a new page with
   the translation, and add som post meta to tell which original page it belongs
   to?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [Firstcode](https://wordpress.org/support/users/diegotheswede/)
 * (@diegotheswede)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/programmatically-create-a-translated-page/#post-8257947)
 * Solved it on my own…
 *     ```
       $newPost = array(
         	'post_title'    => "Translated title",
         	'post_content'  => "Text to publish",
         	'post_status'   => 'publish',
       	'post_type'		=> 'translation',
       	'comment_status'=> 'closed',
         	'post_author'   => 1
       );
   
       // Create post, save the resulting ID
       $new_post = wp_insert_post($newPost, false); 
   
       $parent = '2'; // id of original article
       add_post_meta( $new_post, 'mealingua_translations_post_id', $parent, true ); 
       $languageCode = "de"; //whatever language of the translation
       $term_id = term_exists( $languageCode, 'languages' ); // Get the term ID of language
       if($term_id){ wp_set_post_terms( $new_post, $term_id['term_id'], 'languages', true ); }
       ```
   
    -  This reply was modified 9 years, 7 months ago by [Firstcode](https://wordpress.org/support/users/diegotheswede/).
    -  This reply was modified 9 years, 7 months ago by [Firstcode](https://wordpress.org/support/users/diegotheswede/).
 *  [pavloborysenko](https://wordpress.org/support/users/pavloborysenko/)
 * (@pavloborysenko)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/programmatically-create-a-translated-page/#post-8258950)
 * Hello
 * Great! Thank you for cooperation…
 *  [BeniBook.com](https://wordpress.org/support/users/benibookcom/)
 * (@benibookcom)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/programmatically-create-a-translated-page/#post-8941431)
 * Hello
 * Where must be the code added ?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Programmatically Create a Translated page?’ is closed to new replies.

 * ![](https://ps.w.org/mealingua/assets/icon-256x256.png?rev=1485810)
 * [Mealingua Posts and Pages Translations](https://wordpress.org/plugins/mealingua/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mealingua/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mealingua/)
 * [Active Topics](https://wordpress.org/support/plugin/mealingua/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mealingua/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mealingua/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [BeniBook.com](https://wordpress.org/support/users/benibookcom/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/programmatically-create-a-translated-page/#post-8941431)
 * Status: resolved