static function import_old_team() { global $wpdb; $old_categories_table = $wpdb->prefix . 'our_team_categories'; $old_our_team_table = $wpdb->prefix . 'our_team'; $old_templates_table = TEAM_TEMPLATES; # # Copy old categories over first # $old_team_categories_sql = " SELECT cat_id, name FROM $old_categories_table "; $old_team_categories = $wpdb->get_results($old_team_categories_sql); foreach ($old_team_categories as $category) { wp_insert_term($category->name, 'team_category'); } # # Now copy old team members over # $old_team = OurTeam::get_old_team(); foreach ($old_team as $team) { $new_team_array = array( 'post_title' => $team->name, 'post_content' => $team->bio, 'post_type' => 'team', 'post_status' => 'publish' ); $new_team_post_id = wp_insert_post($new_team_array); update_post_meta($new_team_post_id, 'position', $team->position); update_post_meta($new_team_post_id, 'email', $team->email_address); update_post_meta($new_team_post_id, 'phone_number', $team->phone_number); if (isset($team->category)) { $old_category_sql = " SELECT cat_id, name FROM $old_categories_table WHERE cat_id=$team->category "; $old_category = $wpdb->get_results($old_category_sql); $new_category = get_term_by('name', $old_category[0]->name, 'team_category'); wp_set_post_terms($new_team_post_id, array($new_category->term_id), 'team_category'); } if (isset($team->photo) && $team->photo != '') { $upload_dir = wp_upload_dir(); $upload_dir = $upload_dir['basedir']; $image_path = $upload_dir . '/team-photos/' . $team->photo; $filetype = wp_check_filetype($image_path); $attachment_id = wp_insert_attachment(array( 'post_title' => $team->photo, 'post_content' => '', 'post_status' => 'publish', 'post_mime_type' => $filetype['type'] ), $image_path, $new_team_post_id); set_post_thumbnail($new_team_post_id, $attachment_id); } } # # Now copy templates over # $old_html_template_sql = " SELECT template_code FROM $old_templates_table WHERE template_name='team_index_html' "; $old_html_template_results = $wpdb->get_results($old_html_template_sql); update_option('our_team_html_template', $old_html_template_results[0]->template_code); $old_css_template_sql = " SELECT template_code FROM $old_templates_table WHERE template_name='team_index_css' "; $old_css_template_results = $wpdb->get_results($old_css_template_sql); update_option('our_team_css_template', $old_css_template_results[0]->template_code); # # Now delete the old tables # $drop_tables_sql = " DROP TABLE $old_categories_table, $old_our_team_table, $old_templates_table "; $wpdb->get_results($drop_tables_sql); }