function sfhiv_create_or_update_service_hours($post_ID = false, $post_data, $parent_ID = false)
{
    if (!$post_ID) {
        if (isset($post_data['day_of_week']) && (isset($post_data['start']) && $post_data['start'] != '') && (isset($post_data['end']) && $post_data['end'] != '')) {
            $post_ID = wp_insert_post(array('post_type' => 'sfhiv_service_hour', 'post_title' => "will", 'post_content' => "get", 'post_excerpt' => "overwritten"), true);
        }
    }
    if (!$post_ID) {
        return false;
    }
    if ($parent_ID) {
        $parents = new WP_Query(array('connected_type' => 'service_time', 'connected_items' => $post_ID));
        $found = false;
        foreach ($parents as $parent) {
            if ($parent->ID == $parent_ID) {
                $found = true;
            }
        }
        if (!$found) {
            p2p_create_connection('service_time', array('from' => $parent_ID, 'to' => $post_ID));
        }
        $tax_terms = array('sfhiv_service_category', 'sfhiv_population_category');
        foreach ($tax_terms as $tax) {
            $parent_terms = wp_get_object_terms($parent_ID, $tax, array('fields' => 'slugs'));
            wp_set_object_terms($post_ID, $parent_terms, $tax);
        }
        $parent = get_post($parent_ID);
        $parent_status = get_post_status($parent_ID);
        wp_update_post(array('ID' => $post_ID, 'post_status' => $parent_status, 'post_title' => $parent->post_title, 'post_content' => $parent->post_content, 'post_excerpt' => $parent->post_excerpt));
        $parent_custom = get_post_custom($parent_ID);
        foreach ($parent_custom as $custom_key => $custom_value) {
            delete_post_meta($post_ID, $custom_key);
            foreach ($custom_value as $meta_value) {
                add_post_meta($post_ID, $custom_key, $meta_value);
            }
        }
    }
    // update time
    sfhiv_service_time_of_day_save_post_update($post_ID);
    if (isset($post_data['start'])) {
        $seconds = sfhiv_service_hours_string_to_time($post_data['start']);
        update_post_meta($post_ID, 'sfhiv_service_start', $seconds);
    }
    if (isset($post_data['end'])) {
        $seconds = sfhiv_service_hours_string_to_time($post_data['end']);
        update_post_meta($post_ID, 'sfhiv_service_end', $seconds);
    }
    if (isset($post_data['sfhiv_location'])) {
        sfhiv_location_relation_save($post_ID, $post_data['sfhiv_location']);
    }
    if (isset($post_data['day_of_week'])) {
        wp_set_object_terms($post_ID, $post_data['day_of_week'], 'sfhiv_day_of_week_taxonomy', false);
        if ($parent_ID) {
            wp_set_object_terms($parent_ID, $post_data['day_of_week'], 'sfhiv_day_of_week_taxonomy', true);
        }
    }
}
function sfhiv_location_location_save($post_ID)
{
    if (get_post_type($post_ID) != 'sfhiv_location') {
        return;
    }
    if (isset($_POST['sfhiv_location']) && is_array($_POST['sfhiv_location'])) {
        sfhiv_location_save($post_ID, $_POST['sfhiv_location']);
    }
    $connected_to_location = new WP_Query(array('connected_type' => 'related_location', 'connected_items' => $post_ID));
    if ($connected_to_location->post_count > 0) {
        foreach ($connected_to_location->posts as $post) {
            sfhiv_location_relation_save($post->ID, $post_ID);
        }
    }
}