Skip to content

Instantly share code, notes, and snippets.

@New0
Last active May 29, 2020 08:17
Show Gist options
  • Save New0/69390162c9c745846e346814c25259fc to your computer and use it in GitHub Desktop.
Save New0/69390162c9c745846e346814c25259fc to your computer and use it in GitHub Desktop.
Add the entry ID on CSV Entries export
<?php
// Based on https://calderaforms.com/doc/caldera_forms_admin_csv/
add_filter( 'caldera_forms_admin_csv', function( $csv_data, $form ){
//IMPORTANT change form ID to match your form
if( 'CF5eb5616ea264f' === $form[ 'ID' ] ){
//Add a header for new column
$csv_data[ 'headers' ] = ['entry_id' => 'Entry ID'] + $csv_data[ 'headers' ];
//Add a value for each row for this new column
//Use the index of array whicj corresponds to Entry ID
foreach ( $csv_data[ 'data' ] as $i => $row ) {
//Add the column in data
$row = ['entry_id' => strval($i)] + $row;
$csv_data[ 'data' ][$i] = $row;
}
}
return $csv_data;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment