Preserve data when importing players
Preserve positions, seasons and leagues
This commit is contained in:
@@ -60,6 +60,18 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
|
|
||||||
$meta = array();
|
$meta = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare preservable meta keys.
|
||||||
|
*/
|
||||||
|
$preservable_metas_keys = array(
|
||||||
|
'sp_league',
|
||||||
|
'sp_position',
|
||||||
|
'sp_season',
|
||||||
|
);
|
||||||
|
foreach ( $preservable_metas_keys as $p ) {
|
||||||
|
$meta[ $key ] = '';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( $columns as $index => $key ):
|
foreach ( $columns as $index => $key ):
|
||||||
$meta[ $key ] = sp_array_value( $row, $index );
|
$meta[ $key ] = sp_array_value( $row, $index );
|
||||||
endforeach;
|
endforeach;
|
||||||
@@ -78,6 +90,11 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
||||||
endif;
|
endif;
|
||||||
$id = $player_object->ID;
|
$id = $player_object->ID;
|
||||||
|
// Handle preservable data.
|
||||||
|
foreach ( $preservable_metas_keys as $p ) {
|
||||||
|
$terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) );
|
||||||
|
$meta[ $p ] .= '|' . implode( '|', $terms );
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||||
$id = wp_insert_post( $args );
|
$id = wp_insert_post( $args );
|
||||||
|
|||||||
Reference in New Issue
Block a user