This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook can be used to manipulate the columns that appear in .csv files that are exported.
Note: This filter does not work with the Export Views as CSV add-on, it only works for exporting the entries list CSV. If you are using the add-on, learn more about its list of available hooks.
Usage
add_filter( 'frm_csv_columns', 'remove_id_column', 10, 2 ); function remove_id_column( $headings, $form_id )
Parameters
- $headings (array)
- $form_id (integer)
Examples
Remove ID Column on Export
You can use the example below to remove the ID column and all of it's entry information from the .csv file of a particular form upon export.
add_filter( 'frm_csv_columns', 'remove_id_column', 10, 2 );
function remove_id_column( $headings, $form_id ) {
if ( $form_id == 5 ) { //change 5 to your Form ID
unset( $headings['id'] ); //change id to the header of the column to be removed
}
return $headings;
}
Change the name of a column
If you are importing your CSV into another service, you may need specific names for each column. You can either set your field labels to the names you need, or you can change the names for the export.
add_filter( 'frm_csv_columns', 'change_column_name', 10, 2 );
function change_column_name( $headings, $form_id ) {
$new_labels = array( 25 => 'New label', 26 => 'Another label' ); //change 25 and 26 to your Field IDs, and the labels to the ones you would like to use
foreach ( $new_labels as $field_id => $label ) {
if ( isset( $headings[ $field_id ] ) ) {
$headings[ $field_id ] = $label;
}
}
return $headings;
}
Export specific columns
Use the code below to limit your exported CSV to a few specific columns. Replace 19 with your form ID. Replace 363, 425, 579, and 'id' with the columns you want to export.
add_filter( 'frm_csv_columns', 'export_specific_cols', 10, 2 );
function export_specific_cols( $headings, $form_id ) {
if ( $form_id == 19 ) {
$export_columns = array( 363, 425, 579, 'id' );
foreach ( $headings as $col_key => $data ) {
if ( ! in_array( $col_key, $export_columns ) ) {
unset( $headings[ $col_key ] );
}
}
}
return $headings;
}
Remove All Meta Columns
This example removes all of the meta columns that show things like when the entry was created, by whom, etc.
add_filter( 'frm_csv_columns', 'remove_id_column', 10, 2 );
function remove_id_column( $headings, $form_id ) {
if ( $form_id == 5 ) { //change 5 to your Form ID
unset( $headings['created_at'] );
unset( $headings['updated_at'] );
unset( $headings['user_id'] );
unset( $headings['updated_by'] );
unset( $headings['is_draft'] );
unset( $headings['ip'] );
unset( $headings['id'] ); //change id to the header of the column to be removed
unset( $headings['item_key'] );
}
return $headings;
}
Remove Extra Address Columns on Export
By default, when exporting a form with an Address Field, there will be a column with the complete address, as well as extra columns with the separate parts of the address (line1, line2, city, state, etc.) You can use this custom code to remove the extra columns. Please note, if you have a country dropdown in your Address Field, you will want to uncomment the last column below.
add_filter( 'frm_csv_columns', 'remove_extra_address_columns', 10, 2 );
function remove_extra_address_columns( $headings, $form_id ) {
if ( $form_id == 568 ) { //change 568 to your Form ID
$address_field_id = '3855'; //change 3855 to your Address Field ID
unset( $headings[$address_field_id . '_line1'] );
unset( $headings[$address_field_id . '_line2'] );
unset( $headings[$address_field_id . '_city'] );
unset( $headings[$address_field_id . '_state'] );
unset( $headings[$address_field_id . '_zip'] );
//unset( $headings[$address_field_id . '_country'] ); //uncomment this line if you are using an International Address Layout
}
return $headings;
}
Remove Label Column
Use this code to remove the label column, including all of its entries, when using separate values for checkbox, radio, or dropdown fields.
add_filter( 'frm_csv_columns', 'remove_label_column', 10, 2 );
function remove_label_column( $headings, $form_id ) {
if ( $form_id == 326 ) { //change 326 to your Form ID
unset( $headings['4002_label'] ); //change 4002 to the field ID using separate values
}
return $headings;
}
Rename Name fields on export
Use this code example if you need to change the name of the Name fields for the export.
add_filter( 'frm_csv_columns', 'change_column_name', 10, 2 );
function change_column_name( $headings, $form_id ) {
$name_field_id = 2248; //Replace 1152 with your Name field ID
$headings[ $name_field_id . '_first' ] = 'First name column';
$headings[ $name_field_id . '_last' ] = 'Last name column';
return $headings;
}