Wordpress - import data from CSV table with custom column names (Really Simple CSV importer plugin)
<?php
// Goes in custom rscsvimporter_replace_save_post class before actual writing to db ($ph->add_meta, $ph->add_terms, $ph->update, $ph->insert). See here https://gist.github.com/hissy/1ea54a46fd07be9f4334
if ($meta['Title']) {
$meta_title = $meta['Title'];
$post['post_title'] = trim($meta_title);
}
$tax_map = array(
'Region' => 'regregion',
'Registry' => 'regcat'
);
foreach ($tax_map as $tax_human => $tax_wp) {
if (isset($meta[$tax_human])) {
$meta_terms = explode(',',$meta[$tax_human]);
$_terms = array();
foreach ($meta_terms as $meta_term) {
if (term_exists($meta_term,$tax_wp)) {
$_terms[] = $meta_term;
}
}
$terms[$tax_wp] = $_terms;
unset($meta[$tax_human]);
}
}
$meta_map = array(
'Custom field 1' => 'mysite_cf1',
'Custom field 2' => 'mysite_cf2',
'Custom field 3' => 'mysite_cf3'
);
foreach ($meta_map as $meta_human => $meta_wp) {
if (isset($meta[$meta_human])) {
$meta[$meta_wp] = preg_replace('/\s+/', ' ', trim($meta[$meta_human]));
unset($meta[$meta_human]);
}
}