Created
April 18, 2023 12:19
-
-
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.
This file contains 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
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