Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Created April 18, 2023 12:19
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 woodwardtw/b8b873269860dd6824d754aa190d1a2c to your computer and use it in GitHub Desktop.
Save woodwardtw/b8b873269860dd6824d754aa190d1a2c to your computer and use it in GitHub Desktop.
Import Pressbooks Glossary Items from CSV. Doesn't do location currently, but could if the data structure gets shared.
function pb_add_glossary_item(){
if (($handle = fopen(plugin_dir_path(__FILE__) . "test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
ini_set('auto_detect_line_endings',TRUE);
foreach ($data as $key => $line) {
// code...
$data_array = explode(",", $line);
$args = array(
'post_title' => $data_array[0],
'post_content' => $data_array[1],
'post_type' => 'glossary',
'post_status' => 'publish'
);
wp_insert_post($args);
}
}
fclose($handle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment