1. function office_rw($post_id) {
  2.     // If it is our form has not been submitted, so we dont want to do anything
  3.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || $post->post_status == 'trash')
  4.         return;
  5.     /*Don't do this more than one time*/
  6.     if(get_transient('office-being-created') != 'true'){
  7.         //Temporarily disable this filter
  8.         remove_action('save_post', 'office_rw', 9999, 1);
  9.         $locID = $post_id;
  10.         if($_POST['post_type'] == 'location' && get_post_meta($post_id, '_office-created', true) != 'true'){
  11.             update_post_meta($post_id, '_office-created', 'true');
  12.             set_transient('office-being-created', 'true', 10);
  13.             $office_home = array();
  14.             $office_title = get_the_title($post_id);
  15.             $office_home['post_name'] = sanitize_title_with_dashes($office_title);
  16.             $office_home['post_title'] = $office_title;
  17.             $office_home['post_status'] = 'publish';
  18.             $office_home['post_type'] = 'office';
  19.             $homeID = wp_insert_post($office_home);
  20.             update_post_meta($homeID, 'wpcf-location-list', $locID);
  21.             update_post_meta($homeID, 'wpcf-office-type', 'office-home');
  22.         }
  23.     }
  24.     //restore save
  25.     add_action('save_post', 'office_rw', 9999, 1);
  26. }
  27. add_action('save_post', 'office_rw', 9999, 1);