Last active
August 29, 2015 14:05
-
-
Save certainlyakey/a0db5ba4e86e30dccbdb to your computer and use it in GitHub Desktop.
Wordpress - import data from CSV table with custom column names (Really Simple CSV importer plugin)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment