Formidable Forms

The Most Advanced WordPress Forms Plugin and Form Builder

  • Features
  • Pricing
  • Blog
  • Support
  • Login
  • Get Formidable Forms

frm_csv_where

Last Updated: March 7, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → CSV and XML Management → frm_csv_where
Heads up!
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.

Use this hook to determine which entries will be exported when you export a CSV file.

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.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!
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;
}
  • Usage
  • Parameters
  • Examples
    • Filter by date
    • Filter by current user
    • Filter by User ID in linked entry
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms
Install Formidable Lite

Using WordPress and want to get Formidable Forms for free?

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.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact

Top Features

  • Front End Editor
  • Repeating Fields
  • Views from Entries
  • Calculator Forms
  • Conditional Logic
  • Visual Form Styler
  • Form Templates
  • User Submitted Posts
  • File Upload Forms
  • Spam Protection
  • Multi Page Forms
  • Surveys & Polls
  • Form Graphs & Charts
  • Save and Continue
  • Mobile Forms
  • Stripe Forms
  • PayPal Forms
  • WooCommerce Forms
  • MailChimp Forms
  • User Registration
  • Signature Forms
  • Bootstrap Forms
  • Quiz Maker
  • Zapier Forms
  • Salesforce Forms
  • HubSpot Forms
  • API Webhooks
  • Multilingual Forms
  • Directories

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • Blog

Copyright © 2021 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started