Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('WP_USE_THEMES', false);
- /** Loads the WordPress Environment and Template */
- require( dirname( __FILE__ ) . '/wp-blog-header.php' );
- # Create an associative array of locations to be used later.
- $fp = fopen('ent_regions.csv', 'r');
- $regions = array();
- if ($fp) {
- while (($line = fgets($fp, 4096)) !== false) {
- $items = explode('|', $line);
- $regions[$items[0]] = $items[1];
- }
- fclose($fp);
- }
- else {
- print "ERROR: Could not open regions file.";
- exit;
- }
- # CSV file is export of other database.
- $fp = fopen('outlets.csv', 'r');
- if ($fp) {
- $author_id = 1;
- $location_id = 5; # INCREMENT before wp_insert_post.
- while (($line = fgets($fp, 4096)) !== false) {
- $venue = explode('|', $line);
- #var_dump($venue);
- $location_id++;
- $location_name = $venue[1];
- $slug = strtr(strtolower($location_name), ' ', '-');
- $slug = str_replace('-&-', '-and-', $slug);
- $slug = str_replace('---', '-', $slug);
- $slug = str_replace('--', '-', $slug);
- $description = sprintf('%s%sWebsite: <a href="%s">%s</a>%sEmail: %s%sPhone: +353 0 %s', $venue[13], "\n\n", $venue[6], $venue[6], "\n", $venue[4], "\n", $venue[5]);
- $excerpt = $venue[14];
- $longitude = $venue[18];
- $latitude = $venue[19];
- $address = $venue[2];
- $town = $regions[$venue[3]];
- #print "$location_name - $slug - $excerpt\n$longitude - $latitude\n$address - $town\n\n";
- $post_id = wp_insert_post(
- array(
- 'post_name' => $slug,
- 'post_title' => $location_name,
- 'post_content' => $description,
- 'post_excerpt' => $excerpt,
- 'post_author' => $author_id,
- 'comment_status' => 'closed',
- 'ping_status' => 'closed',
- 'post_status' => 'publish',
- 'post_type' => 'location'
- ));
- #echo "Post id: ".$post_id;
- # Delete post meta to be thorough.
- delete_post_meta($post_id, '_location_status');
- update_post_meta($post_id, '_location_status', '1');
- delete_post_meta($post_id, '_location_longitude');
- update_post_meta($post_id, '_location_longitude', $longitude);
- delete_post_meta($post_id, '_location_latitude');
- update_post_meta($post_id, '_location_latitude', $latitude);
- delete_post_meta($post_id, '_location_country');
- update_post_meta($post_id, '_location_country', 'IE');
- delete_post_meta($post_id, '_location_region');
- update_post_meta($post_id, '_location_region', '');
- delete_post_meta($post_id, '_location_id');
- update_post_meta($post_id, '_location_id', $location_id);
- delete_post_meta($post_id, '_location_address');
- update_post_meta($post_id, '_location_address', $address);
- delete_post_meta($post_id, '_location_town');
- update_post_meta($post_id, '_location_town', $town);
- delete_post_meta($post_id, '_location_state');
- update_post_meta($post_id, '_location_state', 'Co. Cork');
- delete_post_meta($post_id, '_location_postcode');
- update_post_meta($post_id, '_location_postcode', '');
- }
- fclose($fp);
- }
- else {
- print "ERROR: Could not open outlets file.";
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement