Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Exporting filtered submissions using the Ninja Forms Submissions API
// 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