Skip to content

Instantly share code, notes, and snippets.

@kstover
Last active August 29, 2015 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kstover/41e3a9d2068a9e55ba75 to your computer and use it in GitHub Desktop.
Save kstover/41e3a9d2068a9e55ba75 to your computer and use it in GitHub Desktop.
Exporting filtered submissions using the Ninja Forms Submissions API
<?php
// Build an array that we can use for filtering our submitted data.
$args = array(
// fields is a key in our associative array that means we're looking for field values.
'fields' => array(
// 1 represents our field id and 'Kevin' represents the value we're looking to match.
1 => 'Kevin',
// If you want to filter by multiple fields, you'd add them here.
// 2 => 'checked'
),
);
// Subs will contain an array of objects. We just need to get the IDs and pass them to the export method.
$subs = Ninja_Forms()->subs()->get( $args );
// In the future, arrays of subs will be able to be exported without the next step.
//
// Set our ids array to empty.
$ids = array();
foreach ( $subs as $sub ) {
// Add this sub ID to the array.
$ids[] = $sub->sub_id;
}
// Call our export method. (This will cause an immediate download if ran on an init or admin_init hook.)
// If you want to return the CSV as a string instead, you'll pass a second param of bool true.
Ninja_Forms()->subs()->export( $ids );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment