Skip to content

Instantly share code, notes, and snippets.

@jurecuhalev
Created January 29, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jurecuhalev/8693543 to your computer and use it in GitHub Desktop.
Save jurecuhalev/8693543 to your computer and use it in GitHub Desktop.
Returns results of Wordpress Ninja Forms as AJAX friendly JSON ouput (for angular.js)
<?php
$subs = ninja_forms_get_all_subs( 1 );
$fields = ninja_forms_get_fields_by_form_id( 1 );
$json_data = [];
foreach ($subs as $sub_id => $sub) {
$submission_data = array();
$data = unserialize($sub['data']);
$user_values = array();
foreach ($data as $key => $value) {
$user_values[$value['field_id']] = $value['user_value'];
}
foreach ( $fields as $field_id => $field ) {
$user_value = $user_values[$field['id']];
if ($user_value == '') {
continue;
}
$submission_data[] = array(
"label" => $field['data']['label'],
"value" => $user_value,
"type" => $field['type']
);
}
$json_data[] = array(
"id" => $sub['id'],
"items" => array_values($submission_data)
);
echo json_encode(array_values($json_data), JSON_PRETTY_PRINT);
}
?>
@feyazbeck
Copy link

Hello,

Can you please have the kindness and support a newbie to WP? Where would you add this code in WP?

Thank you,
FEY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment