ninja_forms_get_fields_by_form_id
The Ninja Forms ninja forms get fields by form id function.
Description
Parameters (2)
- 0. $form_id
- The form id.
- 1. $orderby — Optional. (string) =>
'ORDER BY `order` ASC'
- The orderby.
Usage
if ( !function_exists( 'ninja_forms_get_fields_by_form_id' ) ) { require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/database.php'; } // The form id. $form_id = null; // The orderby. $orderby = 'ORDER BY `order` ASC'; // NOTICE! Understand what this does before running. $result = ninja_forms_get_fields_by_form_id($form_id, $orderby);
Defined (2)
The function is defined in the following location(s).
- /deprecated/includes/database.php
- function ninja_forms_get_fields_by_form_id($form_id, $orderby = 'ORDER BY `order` ASC') {
- global $wpdb;
- $field_results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".NINJA_FORMS_FIELDS_TABLE_NAME." WHERE form_id = %d ".$orderby, $form_id), ARRAY_A);
- if(is_array($field_results) AND !empty($field_results)) {
- $x = 0;
- $count = count($field_results) - 1;
- while($x <= $count) {
- $field_results[$x]['data'] = unserialize($field_results[$x]['data']);
- $x++;
- }
- }
- return $field_results;
- }
- /includes/deprecated.php
- function ninja_forms_get_fields_by_form_id($form_id, $orderby = 'ORDER BY `order` ASC') {
- $fields = Ninja_Forms()->form( $form_id )->get_fields();
- $field_results = array();
- foreach( $fields as $field ) {
- $field_results[] = array(
- 'id' => $field->get_id(),
- 'form_id' => $form_id,
- 'type' => $field->get_setting( 'type' ),
- 'order' => $field->get_setting( 'order' ),
- 'data' => $field->get_settings(),
- 'fav_id' => null,
- 'def_id' => null,
- );
- }
- return $field_results;
- }