Guest User

code

a guest
Sep 23rd, 2015
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function upload_content($post_id) {
  2. if (get_field('type', $post_id)=='d') {
  3. //$designs = get_field('designs', $post_id);
  4. foreach ($designs as $design) {
  5. $design_post = array(
  6.     'post_title'    => $design['title'],
  7.     'post_content'  => '',
  8.     'post_status'   => 'draft',
  9.     'post_type'     => 'design',
  10.     'post_author'   => 1
  11. );
  12. $photo_post_id = wp_insert_post( $design_post );
  13. update_field('designer', get_field('author', $post_id), $photo_post_id);
  14. update_field('story', $design['story'], $photo_post_id);
  15. update_field('design', $design['design'], $photo_post_id);
  16. }
  17. }
  18. if (get_field('type', $post_id)=='p') {
  19. $photos = get_field('photos', $post_id);
  20. foreach ($photos as $photo) {
  21. $photo_post = array(
  22.     'post_title'    => $photo['title'],
  23.     'post_content'  => '',
  24.     'post_status'   => 'draft',
  25.     'post_type'     => 'photograph',
  26.     'post_author'   => 1
  27. );
  28. $photo_post_id = wp_insert_post( $photo_post );
  29. update_field('photographer', get_field('author', $post_id), $photo_post_id);
  30. update_field('story', $photo['story'], $photo_post_id);
  31. update_field('photograph', $photo['image'], $photo_post_id);
  32. }
  33. }
  34. if (get_field('type', $post_id)=='c') {
  35. $commentaries = get_field('commentaries', $post_id);
  36. foreach ($commentaries as $commentary) {
  37. $commentary_post = array(
  38.     'post_title'    => $commentary['title'],
  39.     'post_content'  => '',
  40.     'post_status'   => 'draft',
  41.     'post_type'     => 'commentary',
  42.     'post_author'   => 1
  43. );
  44. $commentary_post_id = wp_insert_post( $commentary_post );
  45. update_field('commentator', get_field('author', $post_id), $commentary_post_id);
  46. update_field('commentary', $commentary['commentary'], $commentary_post_id);
  47. update_field('verse_reference', $commentary['verse_reference'], $commentary_post_id);
  48. }
  49. }
  50. };
  51. add_filter('acf/save_post', 'upload_content', 10, 3);
RAW Paste Data