• Resolved Firstcode

    (@diegotheswede)


    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

    (@diegotheswede)

    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.
    • This reply was modified 9 years, 7 months ago by Firstcode.

    Hello

    Great! Thank you for cooperation…

    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.