Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2. function duplicate_und_translate($post_id, $lang)
  3. {
  4. $exists = pll_get_post($post_id, $lang);
  5. if (!$exists) {
  6.  
  7. $title = get_the_title($post_id);
  8. $oldpost = get_post($post_id);
  9.  
  10. $post = array(
  11. 'post_title' => $title,
  12. 'post_status' => 'publish',
  13. 'post_type' => $oldpost->post_type,
  14. 'post_content' => $oldpost->post_content,
  15. 'post_author' => 1
  16. );
  17. $new_post_id = wp_insert_post($post);
  18.  
  19.  
  20. $data = get_post_custom($post_id);
  21. foreach ($data as $key => $values) {
  22. foreach ($values as $value) {
  23. add_post_meta($new_post_id, $key, $value);
  24. }
  25. }
  26.  
  27. PLL()->model->set_post_language($new_post_id, $lang);
  28. PLL()->model->post->save_translations($new_post_id, array('en' => $post_id));
  29.  
  30. wp_update_post([
  31. 'ID' => $new_post_id,
  32. 'post_name' => $oldpost->post_name
  33. ]);
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement