rendered paste body<?php/* Use this to reset for a second upload */// update_option('demo-data-imported',false);if (is_admin()){ if (!get_option('demo-data-imported'))cms_create_default();}function cms_create_default(){ /* insert the posts if file exists */ /* title category status excert content tags */ $fileName = STYLESHEETPATH.'/import/posts.txt'; if (file_exists($fileName)){ //$readfile[0] would be the first line and the headers the array begins at 0 $readFile = file($fileName); if ($readFile){ for ($k=0; $k<=count($readFile)-1; $k++) { if ($k != 0){ $fields = split("\t",$readFile[$k]); cms_insert_post($fields); } } } } update_option('demo-data-imported',true);}function cms_insert_post($postFields){ $title = trim($postFields[0]); $category = trim($postFields[1]); $status = trim($postFields[2]); $excert = trim($postFields[3]); $content = trim($postFields[4]); $tags = trim($postFields[5]); $catID=array(); if ($category) $catID[] = cms_get_categoryID($category); if ($status){ $status='publish'; }else{ $status='draft'; } $cms_post = array(); $cms_post['post_title'] = $title; $cms_post['post_content'] = $content; $cms_post['post_status'] = $status; $cms_post['post_author'] = 1; $cms_post['post_category'] = $catID; $post_ID = wp_insert_post($cms_post); /* insert any tags associated with the post */ if ($tags && $post_ID) wp_set_post_terms( $post_ID, $tags);}function cms_get_categoryID($catName){ global $wpdb; $category_slug = str_replace(" ","-",$catName); $category_slug = strtolower($category_slug); $thevalue = $wpdb->get_var( "SELECT term_id FROM $wpdb->terms WHERE slug = '" . $category_slug . "'" ); if ($thevalue) { return $thevalue; }else{ return ""; }}?>