Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_csv_where

Use this hook to determine which entries will be exported when you export a CSV of Formidable entries from your site. You can export a CSV from your form's Entries tab or from the Formidable Import/Export page.

Usage

add_filter('frm_csv_where', 'limit_csv_export', 10, 2);

Parameters

  • $where (string)
  • $args (array) => ['form_id' (int)]

Examples

Filter by date

Use this code to export only those entries that were created in January 2015. This example applies to a particular form. Change 129 to the ID of your form (in two places).

add_filter('frm_csv_where', 'limit_csv_by_date', 10, 2);
function limit_csv_by_date($where, $args){
	if ( $args['form_id'] == 19 ) {// Change 19 to the ID of your form
		$where['form_id'] = 19;// Change 19 to the ID of your form
		$where['created_at >'] = '2015-01-01 00:00:00';
		$where['created_at <'] = '2015-01-31 23:59:59';
	}
	return $where;
}

Filter by current user

Use this code to export the entries created by the current user. The user must have permission to "View Entries from the Admin area" in order for this to work.

add_filter('frm_csv_where', 'limit_csv_to_current_user', 10, 2);
function limit_csv_to_current_user($where, $args){
	if ( $args['form_id'] == 19 ) {// Change 19 to the ID of your form
		$current_user = wp_get_current_user();
		$where['form_id'] = 19;// Change 19 to the ID of your form again
		$where['user_id'] =  $current_user->ID;
	}
	return $where;
}

Filter by User ID in linked entry

Use the code below to filter a CSV so it only includes entries where a Dynamic field has an entry selected that was created by the current user. Replace 1003 with the ID of your form, replace 19 with the ID of the form that the Dynamic field gets its value from, and replace 12666 with the ID of the Dynamic field.

add_filter('frm_csv_where', 'filter_by_linked_id', 10, 2);
function filter_by_linked_id( $where, $args ) {
	if ( $args['form_id'] == 1003 ) {// Change 19 to the ID of your form
		$user_id = get_current_user_id();
		$linked_form_id = 19;
		$linked_id_where = array( 'user_id' => $user_id, 'form_id' => $linked_form_id );
		$linked_ids = FrmDb::get_col( 'frm_items', $linked_id_where, 'id' );

		if ( is_array( $linked_ids ) ) {
			global $wpdb;
			$dynamic_field_id = 12666;
			$query = 'SELECT e.id FROM ' . $wpdb->prefix . 'frm_items e';
			$query .= ' INNER JOIN ' . $wpdb->prefix . 'frm_item_metas m ON e.id=m.item_id';
			$query .= ' WHERE m.field_id=' . $dynamic_field_id;
			$query .= ' AND m.meta_value IN (' . implode( ',', $linked_ids ) . ')';

			$entry_ids = $wpdb->get_col( $query );
		} else {
			$entry_ids = false;
		}

		if ( is_array( $entry_ids ) ) {
			$where['id'] = $entry_ids;
		} else if ( ! $entry_ids ) {
			$where['id'] = 0;
		}
	}
	return $where;
}
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms