Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. function multilingual_post_creation(){
  2.  
  3. global $sitepress;
  4. /**
  5. /**
  6. Creating first post in english
  7. */
  8.  
  9. //arguments for post creation
  10. $def_args = array(
  11. 'post_title' => '[en]Test post - ' . date("d.m - H:i:s"),
  12. 'post_content' => 'Text in default language goes here',
  13. 'post_status' => 'publish',
  14. 'post_type' => 'post'
  15.  
  16. );
  17. //creating post with arguments above and assign post id to $def_post_id
  18. $def_post_id = wp_insert_post($def_args);
  19. $def_trid = $sitepress->get_element_trid($def_post_id);
  20.  
  21. /**
  22. Creating translation of first post in another language. Right now for russian
  23. */
  24.  
  25. //arguments for post creation
  26. $ru_args = array(
  27. 'post_title' => '[ru]Test post - ' . date("d.m - H:i:s"),
  28. 'post_content' => 'Text in russian language goes here',
  29. 'post_status' => 'publish',
  30. 'post_type' => 'post'
  31.  
  32. );
  33. //creating post with arguments above and assign post id to $ru_post_id
  34. $ru_post_id = wp_insert_post($ru_args);
  35.  
  36. //change language and trid of second post to match russian and default post trid
  37. $sitepress->set_element_language_details($ru_post_id, 'post_post', $def_trid, 'ru');
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement