add_action('init', 'any_bulk_import_archery_locations'); function any_bulk_import_archery_locations() { if (get_option('archery_locations_imported')) return; $csv_file = get_stylesheet_directory() . '/data/archery_shops.csv'; if (!file_exists($csv_file)) return; $csv = array_map('str_getcsv', file($csv_file)); $headers = array_map('trim', array_shift($csv)); foreach ($csv as $row) { // Skip if columns don't match headers if (count($row) !== count($headers)) continue; $data = array_combine($headers, $row); if (empty($data['name'])) continue; $post_id = wp_insert_post([ 'post_title' => $data['name'], 'post_type' => 'locations', 'post_status' => 'publish', 'post_content' => build_location_html_content($data), ]); if (is_wp_error($post_id) || !$post_id) continue; if (!empty($data['state'])) wp_set_object_terms($post_id, $data['state'], 'state'); if (!empty($data['city'])) wp_set_object_terms($post_id, $data['city'], 'city'); if (!empty($data['photo'])) { media_sideload_featured_image($data['photo'], $post_id); } } update_option('archery_locations_imported', true); } Archery Near You