Created
July 21, 2017 15:26
-
-
Save aolin480/b7aba34deec15a3824529f3274fc6a9b to your computer and use it in GitHub Desktop.
Creates an English post, and attaches a Russian translation to English post programatically. Thanks janekS!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function multilingual_post_creation(){ | |
global $sitepress; | |
/** | |
/** | |
Creating first post in english | |
*/ | |
//arguments for post creation | |
$def_args = array( | |
'post_title' => '[en]Test post - ' . date("d.m - H:i:s"), | |
'post_content' => 'Text in default language goes here', | |
'post_status' => 'publish', | |
'post_type' => 'post' | |
); | |
//creating post with arguments above and assign post id to $def_post_id | |
$def_post_id = wp_insert_post($def_args); | |
$def_trid = $sitepress->get_element_trid($def_post_id); | |
/** | |
Creating translation of first post in another language. Right now for russian | |
*/ | |
//arguments for post creation | |
$ru_args = array( | |
'post_title' => '[ru]Test post - ' . date("d.m - H:i:s"), | |
'post_content' => 'Text in russian language goes here', | |
'post_status' => 'publish', | |
'post_type' => 'post' | |
); | |
//creating post with arguments above and assign post id to $ru_post_id | |
$ru_post_id = wp_insert_post($ru_args); | |
//change language and trid of second post to match russian and default post trid | |
$sitepress->set_element_language_details($ru_post_id, 'post_post', $def_trid, 'ru'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment