Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created September 9, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/5038ff3215675147dfe20fbca416ad0e to your computer and use it in GitHub Desktop.
Save kimcoleman/5038ff3215675147dfe20fbca416ad0e to your computer and use it in GitHub Desktop.
Duplicate TEAE usermeta fields to xProfile Fields
<?php
/**
* Duplicate TEAE usermeta fields to xProfile Fields
*
*/
function teae_duplicate_usermeta_to_xprofile( ) {
global $wpdb;
$fields = array(
'alternate_phone'=>'261',
'body_number_(jal/sal)_1'=>'205',
'body_number_(jal/sal)_2'=>'206',
'body_number_(jal/sal)_3'=>'207',
'body_number_(jal/sal)_4'=>'208',
'body_number_(jal/sal)_5'=>'209',
'body_style_1'=>'8',
'body_style_2'=>'35',
'body_style_3'=>'67',
'body_style_4'=>'85',
'body_style_5'=>'108',
'color_code_at_build_1'=>'15',
'color_code_at_build_2'=>'30',
'color_code_at_build_3'=>'74',
'color_code_at_build_4'=>'97',
'color_code_at_build_5'=>'115',
'comments_1'=>'18',
'comments_2'=>'34',
'comments_3'=>'78',
'comments_4'=>'101',
'comments_5'=>'119',
'current_color_1'=>'20',
'current_color_2'=>'31',
'current_color_3'=>'75',
'current_color_4'=>'98',
'current_color_5'=>'116',
'engine_number_1'=>'14',
'engine_number_2'=>'29',
'engine_number_3'=>'73',
'engine_number_4'=>'95',
'engine_number_5'=>'114',
'joint_member_first_name'=>'259',
'joint_member_second_name'=>'260',
'marque_1'=>'3',
'marque_2'=>'22',
'marque_3'=>'63',
'marque_4'=>'80',
'marque_5'=>'103',
'model_1'=>'4',
'model_2'=>'23',
'model_3'=>'258',
'model_4'=>'81',
'model_5'=>'104',
'modifications_1'=>'17',
'modifications_2'=>'33',
'modifications_3'=>'77',
'modifications_4'=>'100',
'modifications_5'=>'118',
'pmpro_baddress1'=>'198',
'pmpro_baddress2'=>'199',
'pmpro_bcity'=>'200',
'pmpro_bphone'=>'203',
'pmpro_bstate'=>'201',
'pmpro_bzipcode'=>'202',
'purchase_date_1'=>'7',
'purchase_date_2'=>'26',
'purchase_date_3'=>'66',
'purchase_date_4'=>'84',
'purchase_date_5'=>'107',
'region'=>'149',
'sub-model_or_series_1'=>'5',
'sub-model_or_series_2'=>'24',
'sub-model_or_series_3'=>'64',
'sub-model_or_series_4'=>'82',
'sub-model_or_series_5'=>'105',
'tac#_(if_applicable)_1'=>'16',
'tac#_(if_applicable)_2'=>'32',
'tac#_(if_applicable)_3'=>'76',
'tac#_(if_applicable)_4'=>'99',
'tac#_(if_applicable)_5'=>'117',
'teae_number'=>'204',
'vin_1'=>'13',
'vin_2'=>'28',
'vin_3'=>'72',
'vin_4'=>'94',
'vin_5'=>'113',
'year_of_manufacture_1'=>'6',
'year_of_manufacture_2'=>'25',
'year_of_manufacture_3'=>'65',
'year_of_manufacture_4'=>'83',
'year_of_manufacture_5'=>'106',
);
foreach ( $fields as $meta_key => $field_ID ) {
$sqlQuery = 'SELECT * FROM $wpdb->usermeta WHERE meta_key = "' . esc_sql( $meta_key ) . '"';
$fields = $wpdb->get_results( $sqlQuery );
foreach ( $fields as $field ) {
//switch for type
$x_field = xprofile_get_field( $field_ID, $field->user_id );
if ( ! empty( $x_field ) )
xprofile_set_field_data( $x_field, $field->user_id, $field->meta_value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment