Created
May 9, 2013 00:52
-
-
Save Dare-NZ/5544790 to your computer and use it in GitHub Desktop.
A php file that takes a WP table and saves as a CSV
This file contains hidden or 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
<?php | |
require_once('../../../../wp-load.php'); | |
global $wpdb; | |
$wpdb->show_errors(); | |
$table_name = $wpdb->prefix . "arg_signups"; | |
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { | |
newsletter_install(); | |
} | |
$signups = $wpdb->get_results("SELECT * FROM `$table_name` ORDER BY id"); | |
$header = "id\tname\temail\t"; | |
$data = ''; | |
if(!empty($signups)) { | |
foreach ($signups as $signup) { | |
$line = "\"" . $signup->id . "\"\t"; | |
$line .= "\"" . $signup->name . "\"\t"; | |
$line .= "\"" . $signup->email . "\"\t"; | |
$data .= $line . "\n"; | |
} | |
} else { | |
$data = "\n(0) Records Found!\n"; | |
} | |
header("Content-type: application/octet-stream"); | |
header("Content-Disposition: attachment; filename=signups.csv"); | |
header("Pragma: no-cache"); | |
header("Expires: 0"); | |
print "$header\n$data"; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment