diff --git a/functions/exporter.php b/functions/exporter.php
index 405da84..a2fd0a3 100644
--- a/functions/exporter.php
+++ b/functions/exporter.php
@@ -1,102 +1,100 @@
$ccsve_generate_post_type, 'post_status' => 'publish', 'posts_per_page' => -1));
- // Count the number of instances of the custom post type
- $ccsve_count_posts = count($ccsve_generate_query);
-
- // Build an array of the custom field values
- $ccsve_generate_value_arr = array();
- $i = 0;
- foreach ($ccsve_generate_query as $post): setup_postdata($post);
- $post->permalink = get_permalink($post->ID);
- $post->post_thumbnail = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
- // get the standard wordpress fields for each instance of the custom post type
- foreach($post as $key => $value) {
- if(in_array($key, $ccsve_generate_std_fields['selectinput'])) {
- $ccsve_generate_value_arr[$key][$i] = $post->$key;
- }
- }
- // get the custom field values for each instance of the custom post type
- $ccsve_generate_post_values = get_post_custom($post->ID);
- foreach ($ccsve_generate_custom_fields['selectinput'] as $key) {
- // check if each custom field value matches a custom field that is being exported
- if (array_key_exists($key, $ccsve_generate_post_values)) {
- // if the the custom fields match, save them to the array of custom field values
- $ccsve_generate_value_arr[$key][$i] = $ccsve_generate_post_values[$key]['0'];
-
- }
-
- }
- // get custom taxonomy information
- foreach($ccsve_generate_tax_terms['selectinput'] as $tax) {
- $names = array();
- $terms = wp_get_object_terms($post->ID, $tax);
- foreach($terms as $t) {
- $names[] = $t->name;
- }
- $ccsve_generate_value_arr[$tax][$i] = implode(',', $names);
- }
- $i++;
-
- endforeach;
- // create a new array of values that reorganizes them in a new multidimensional array where each sub-array contains all of the values for one custom post instance
- $ccsve_generate_value_arr_new = array();
-
- foreach($ccsve_generate_value_arr as $value) {
- $i = 0;
- while ($i <= ($ccsve_count_posts-1)) {
- $ccsve_generate_value_arr_new[$i][] = $value[$i];
- $i++;
- }
- }
+ // Get the custom post type that is being exported
+ $ccsve_generate_post_type = get_option('ccsve_post_type');
+ // Get the custom fields (for the custom post type) that are being exported
+ $ccsve_generate_custom_fields = get_option('ccsve_custom_fields');
+ $ccsve_generate_std_fields = get_option('ccsve_std_fields');
+ $ccsve_generate_tax_terms = get_option('ccsve_tax_terms');
+ // Query the DB for all instances of the custom post type
+ $ccsve_generate_query = get_posts(array('post_type' => $ccsve_generate_post_type, 'post_status' => 'publish', 'posts_per_page' => -1));
+ // Count the number of instances of the custom post type
+ $ccsve_count_posts = count($ccsve_generate_query);
- // build a filename based on the post type and the data/time
- $ccsve_generate_csv_filename = $ccsve_generate_post_type.'-'.date('Ymd_His').'-export.csv';
-
- //output the headers for the CSV file
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header('Content-Description: File Transfer');
- header("Content-type: text/csv");
- header("Content-Disposition: attachment; filename={$ccsve_generate_csv_filename}");
- header("Expires: 0");
- header("Pragma: public");
-
- //open the file stream
- $fh = @fopen( 'php://output', 'w' );
-
- $headerDisplayed = false;
-
- foreach ( $ccsve_generate_value_arr_new as $data ) {
- // Add a header row if it hasn't been added yet -- using custom field keys from first array
- if ( !$headerDisplayed ) {
- fputcsv($fh, array_keys($ccsve_generate_value_arr));
- $headerDisplayed = true;
+ // Build an array of the custom field values
+ $ccsve_generate_value_arr = array();
+ $i = 0;
+ foreach ($ccsve_generate_query as $post): setup_postdata($post);
+ $post->permalink = get_permalink($post->ID);
+ $post->post_thumbnail = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
+ // get the standard wordpress fields for each instance of the custom post type
+ foreach($post as $key => $value) {
+ if(in_array($key, $ccsve_generate_std_fields['selectinput'])) {
+ $ccsve_generate_value_arr[$key][$i] = $post->$key;
}
-
+ }
+ // get the custom field values for each instance of the custom post type
+ $ccsve_generate_post_values = get_post_custom($post->ID);
+ foreach ($ccsve_generate_custom_fields['selectinput'] as $key) {
+ // check if each custom field value matches a custom field that is being exported
+ if (array_key_exists($key, $ccsve_generate_post_values)) {
+ // if the the custom fields match, save them to the array of custom field values
+ $ccsve_generate_value_arr[$key][$i] = $ccsve_generate_post_values[$key]['0'];
+
+ }
+
+ }
+ // get custom taxonomy information
+ foreach($ccsve_generate_tax_terms['selectinput'] as $tax) {
+ $names = array();
+ $terms = wp_get_object_terms($post->ID, $tax);
+ foreach($terms as $t) {
+ $names[] = $t->name;
+ }
+ $ccsve_generate_value_arr[$tax][$i] = implode(',', $names);
+}
+$i++;
+
+endforeach;
+ // create a new array of values that reorganizes them in a new multidimensional array where each sub-array contains all of the values for one custom post instance
+$ccsve_generate_value_arr_new = array();
+
+foreach($ccsve_generate_value_arr as $value) {
+ $i = 0;
+ while ($i <= ($ccsve_count_posts-1)) {
+ $ccsve_generate_value_arr_new[$i][] = $value[$i];
+ $i++;
+}
+}
+
+ // build a filename based on the post type and the data/time
+$ccsve_generate_csv_filename = $ccsve_generate_post_type.'-'.date('Ymd_His').'-export.csv';
+
+ //output the headers for the CSV file
+header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+header('Content-Description: File Transfer');
+header("Content-type: text/csv");
+header("Content-Disposition: attachment; filename={$ccsve_generate_csv_filename}");
+header("Expires: 0");
+header("Pragma: public");
+
+ //open the file stream
+$fh = @fopen( 'php://output', 'w' );
+
+$headerDisplayed = false;
+
+foreach ( $ccsve_generate_value_arr_new as $data ) {
+ // Add a header row if it hasn't been added yet -- using custom field keys from first array
+ if ( !$headerDisplayed ) {
+ fputcsv($fh, array_keys($ccsve_generate_value_arr));
+ $headerDisplayed = true;
+ }
+
// Put the data from the new multi-dimensional array into the stream
- fputcsv($fh, $data);
+ fputcsv($fh, $data);
}
// Close the file stream
fclose($fh);
// Make sure nothing else is sent, our file is done
exit;
- }
+}
diff --git a/settings.php b/settings.php
index 14c00d4..2e2eb73 100644
--- a/settings.php
+++ b/settings.php
@@ -1,210 +1,211 @@
true,
- );
+
+ $args=array(
+ 'public' => true,
+ );
// Get the field name from the $args array
- $items = get_post_types($args);
+ $items = get_post_types($args);
// Get the value of this setting
- $options = get_option('ccsve_post_type');
+ $options = get_option('ccsve_post_type');
// echo a proper input type="text"
- foreach ($items as $item) {
- $checked = ($options==$item) ? ' checked="checked" ' : '';
- echo '';
- echo '';
- echo ' ';
- }
+ foreach ($items as $item) {
+ $checked = ($options==$item) ? ' checked="checked" ' : '';
+ echo '';
+ echo '';
+ echo ' ';
+ }
} // END public function settings_field_input_text($args)
public function settings_field_select_std_fields()
{
- $ccsve_post_type = get_option('ccsve_post_type');
- $fields = generate_std_fields($ccsve_post_type);
- $ccsve_std_fields =get_option('ccsve_std_fields');
- $ccsve_std_fields_num = count($fields);
- echo '